Simplest way to profile a PHP script What's the easiest way to profile a PHP script? I'd love tacking something on that shows me a dump of all function calls and how long they took but I'm also OK with putting something around specific functions. I tried experimenting with the microtime function: $then = microtime(); myFunc(); $now = microtime(); echo sprintf("Elapsed: %f", $now-$then); but that sometimes gives me negative results. Plus it's a lot of trouble to sprinkle that all over my code. ==Answer :
undefined
Does PHP have built-in data structures? I'm looking at the PHP Manual, and I'm not seeing a section on data structures that most languages have, such as lists and sets. Am I just blind or does PHP not have anything like this built in? Solution : The only native data structure in PHP is array. Fortunately, arrays are quite flexible and can be used as hash tables as well. http://www.php.net/array However, there is SPL which is sort of a clone of C++ STL. http://www.php.net/manual/en/book.spl.php
undefined
How do you debug PHP scripts? How do you debug PHP scripts? I am aware of basic debugging such as using the Error Reporting. The breakpoint debugging in PHPEclipse is also quite useful. What is the best (in terms of fast and easy) way to debug in phpStorm or any other IDE? Solution : Try Eclipse PDT to setup an Eclipse environment that has debugging features like you mentioned. The ability to step into the code is a much better way to debug then the old method of var_dump and print
undefined
Make XAMPP/Apache serve file outside of htdocs Is it possible to configure xampp to serve up a file outside of the htdocs directory? For instance, say I have a file located as follows: C:\projects\transitCalculator\trunk\TransitCalculator.php and my xampp files are normally served out from: C:\xampp\htdocs\ (because that's the default configuration) Is there some way to make Apache recognize and serve up my TransitCalculator.php file without moving it under htdocs? Preferably I'd like Apache to serve up/have access to the entire contents of the projects directory, and I don't want to move the projects
undefined
How can I get at the matches when using preg_replace in PHP? I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using preg_replace for extract and wrapping purposes, but it's not outputting anything. preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str) Solution : Put the match in parentheses, like this: preg_replace("/([A-Z])/", "<span class=\"initial\">$1</span>", $str)
undefined
How to include PHP files that require an absolute path? I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php Now, I use those objects in both script.php and /soap/soap.php, I could move them, but I want the directory structure like that for a specific reason. When executing script.php the include path is inc/include.php and when executing /soap/soap.php it's ../inc, absolute paths work, /mnt/webdev/[project name]/inc/include1.php... But it's an ugly solution if I ever want to move the directory to a different location.
undefined
How to easily consume a web service from PHP Is there available any tool for PHP which can be used to generate code for consuming a web service based on its WSDL? Something comparable to clicking "Add Web Reference" in Visual Studio or the Eclipse plugin which does the same thing for Java. Solution : I've had great success with wsdl2php. It will automatically create wrapper classes for all objects and methods used in your web service.