jQuery serverCookieJar
Introduction
¶
After work on the jQuery plugin cookieJar it was pointed out that cookie data is sent with every request and that cookies have a limit of 4KB, this got me thinking. What about storing this information on the server.
This is done by making a request to the server when the page first loads with a request for the data. Then only any changes are sent to the server when something changes. This adds the size of this data for the page to the down traffic (much faster than the up traffic) occurring just once per page, rather than the up traffic for every request on a page.
Requirements
¶
Requirements to use this code
Compatibility
¶
So far the plugin has been tested in windows using the following browsers.
- IE 6, 7
- FF 1.5, 2, 3
- Opera 9
- Safari 3
Usage
¶
This plugin is designed as an alternative to cookieJar. See it’s doc’s and usage examples
Note:
This plugin uses async:false option on ajax. This means when a serverCookieJar object is created for the cookieJar it makes a request to the server for that cookieJar, the browser will pause until the cookieJar has been retrieved from the server, the larger the serverCookieJar or the slower the server the longer this will take.
Example
¶
jquery.servercookiejar.example.html
Downloads
¶
Here are the downloads
jquery.servercookiejar.js (7.2KB)
jquery.servercookiejar.pack.js (2.4KB)
jquery.servercookiejar.php (0.7KB)
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).''; |
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.''; var_dump($row); echo ''; } echo 'Row count: '.count($csv).''; |
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.''; var_dump($row); echo ''; } echo 'Row count: '.count($csv).''; |
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.''; var_dump($row); echo ''; } echo 'Row count: '.count($csv).''; |
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)