Xdebug 2 released
After almost four years of work, Xdebug 2 is finally ready. With improved functionality and many new features it is ready to totally change the way you develop in PHP. Some of the new features and updates include improved stack traces, execution traces to files, code coverage analysis and much improved remote debugging support. Xdebug’s documentation has also been rewritten for more clarity.As with most open source projects, it’s very hard to know who are actually the users of the project. As I would like to know my users better, I would invite everybody who finds Xdebug useful to send me a postcard with their location. (Address is here at the top of the page). I am looking forwards to find out who you are!
Good news for all. I’m happy as the bug I reported has been fixed. This is their first stable release of version 2, at last, but it was worth the wait!
Good work guys.
download it at http://xdebug.org/
CSV & Standard PHP Library
Introduction ¶
I’ve been spending quite some time working with the Zend framework, I must say it’s about the only PHP framework I’ve got on with. I really like the directory structure lay out. With that kind of directory layout and more rigid class names I’m not really sold on the whole idea that we need namespaces from php6.
Standard PHP Library ¶
Any way the SPL (Standard PHP Library) is another little gem that is hidden away in PHP 5. Due the PHP manual not being all that great with class structured documentation they’ve provided some where else for the SPL documentation.
SPL has been around for years now, but it’s still one of those hidden away features that we don’t all know about. I briefly discovered it some years ago, but have only recently started using.
A full introduction to the SPL can be found at sitepoint from article written by Harry Fuecks, who does some other very good PHP related articles, well worth the read.
CSV Classes ¶
There are probably many other PHP CSV classes out there. But I think the ones I provide here are the simplest and easiest I’ve seen. The are a few classes in the package but the ones you’ll be interested in are.
- jDempster_Csv_File
- jDempster_Csv_String
- jDempster_Csv_Url
- jDempster_Csv_Zip_File
- jDempster_Csv_Zip_Url
While creating the classes I have taken speed an memory into account so don’t worry it doesn’t do anything crazy like load the entire file into memory first. These CSV classes have been tested with CSV files of over 100MB.
Requirements ¶
The classes are designed to work on there own or with the Zend framework.
The classes have been tested to work with PHP 5.2.3 on Linux and Windows.
The jDempster_Csv_String requires at least PHP 5.1.
The jDempster_Csv_Zip_* classes require PHP 5.2.
Note: For the classes to read lines correctly auto_detect_line_endings needs to be on. A simple ini_set can turn this on at runtime.
Usage ¶
The following are some sample usage. The classes are commented in a docblock style for extra help and information.
Example 1.
1 2 3 4 5 6 | $filename = 'csv_file.csv'; $csv = new jDempster_Csv_File($filename, true); foreach ($csv as $row) { var_dump($row); } echo 'Row count: '.count($csv).'<br />'; |
Example 2.
1 2 3 4 5 6 7 8 | $filename = 'csv_file.csv'; $csv = new jDempster_Csv_File($filename, true); foreach ($csv as $rowNumber => $row) { echo $rowNumber.'<br />'; var_dump($row); echo '<br />'; } echo 'Row count: '.count($csv).'<br />'; |
Example 3.
1 2 3 4 5 6 7 8 | $csvData = file_get_contents($filename); $csv = new jDempster_Csv_String($csvData, true); foreach ($csv as $rowNumber => $row) { echo $rowNumber.'<br />'; var_dump($row); echo '<br />'; } echo 'Row count: '.count($csv).'<br />'; |
Example 4.
1 2 3 4 5 6 7 8 | $csvZip = 'csv_zipfile.zip'; $csv = new jDempster_Csv_Zip_File($csvZip, true); foreach ($csv as $rowNumber => $row) { echo $rowNumber.'<br />'; var_dump($row); echo '<br />'; } echo 'Row count: '.count($csv).'<br />'; |
As you can see, the object is used as you would any array. It can be used in while loops, for loops etc etc.
Any problems or comments please
Downloads ¶
jdempster_csv.zip (6.50 KB)Xdebug __get memory leak
Just spent a few hours trying to work out why some php scripts ended up using more than 300MB of memory when the php.ini memory limit was set to 50MB.
I thought it was a leak in php, after alot of testing I found that in actual fact Xdebug 2.0.0RC4 was causing the leak.
1 2 3 4 5 6 7 8 9 10 11 | <?php class test1 { public function __get($name) { return; } } $test = new test1(); while(true) { $test->test; } |