For details head over at this link
Thursday, July 23, 2009
Friday, July 3, 2009
Using PHP's glob() function to find files in a directory
Here is the details to get a list of all the files in a given directory.
Wednesday, June 10, 2009
Setting cookies with jQuery
For setting a cookie in the client side we usually go for normal javascript. Here i found one article where we can use jquery plugin to do the cookie manipulation. The code is very use and easy to manipulate. For more details check it here
Monday, June 1, 2009
Fastest way to build an HTML string
There are different ways we can build an HTML string . I was going through one article which clearly gives the different ways including benchmark results. For more information head over at this link
Tuesday, May 12, 2009
MySQL: Find records in one table that are not in another
Using NOT EXISTS is much faster than using LEFT JOIN to find records in one table that are not in another. Head over at for more details on the same
Tuesday, March 10, 2009
PHP micro-optimization tips
- calling an object method is faster then traping it with with "__call"
- calling a "static" method is faster then an object method
- calling a function is faster then calling a static method
- accessing a local variable is faster then then a global variable
- accessing a global variable is faster then an object property
- accessing an object property is faster then trapping it with "__get" and "__set"
- accessing an initialized variable is faster then accessing an uninitialized variable
- absolute paths in "include" and "require" are faster then relative
- merging several scripts in one file and then including it is faster then several includes
- "switch" is faster then "if ... else if ..." in some cases
- do not use regexs for simple string processing tasks
- avoid @ (error control operator)
- avoid notices and warnings in your scripts
- avoid unused variables and unused method parameters
- adding method parameter increases calling time
- adding method parameter type hint increases calling time
- unset variables that contain large amount of data or circular references
- $_SERVER['REQUEST_TIME'] contains script startup time
- cache page output or result of resource-consuming functions
- "echo" is faster than "print"
- "echo" accepts several arguments, you can use it instead of string concatenation
- "ob_start()" and "ob_end_clean()" is may be better then several string concatenations
- strings in single quotes ('...') are processed faster then strings in double quotes ("...")
- pre-increment (++$i) is faster then post-increment ($i++)
- "isset" is a faster alternative to "array_key_exists"
- an array is a faster alternative to a class with several fields
- "foreach" is better then "for" in many cases
- open resources (files, database connections, sockets) right before using them, free resources as soon as you do not need them
- do not fetch database fields which you do not use in your script
- use prepared database statements
- combine several queries in one when database supports it
Tuesday, December 23, 2008
Data structures in PHP 5.3
In the programming world there are quite a few well understood and explored data structures. Which are commonly used in tons of applications, still the only things PHP offered till 5.3 in regards to structuring data were arrays (more precise: hash tables) and objects. So people had to either abuse them for other structures or implement the structures themselves on top of these. Thanks to Etienne things now are changing and PHP's Standard PHP Library (SPL) extension will offer quite a few standard implementations of data structures. The implemented data structures are implemented using these classes:
* SplDoublyLinkedList
* SplStack
* SplQueue (SplPriorityQueue)
* SplHeap (SplMinHeap, SplMaxHeap)
* SplFixedArray
For more details head over at http://schlueters.de/blog/archives/90-Data-structures-in-PHP-5.3.html
* SplDoublyLinkedList
* SplStack
* SplQueue (SplPriorityQueue)
* SplHeap (SplMinHeap, SplMaxHeap)
* SplFixedArray
For more details head over at http://schlueters.de/blog/archives/90-Data-structures-in-PHP-5.3.html
Wednesday, December 17, 2008
Usage of IF condition in mysql
Scenario:
Suppose we have the field in the table lets say status which has the ENUM value ACTIVE,INACTIVE.Usually after getting the value of this field(through the query)
we used to write return ($result['status']=='ACTIVE')?1:0 in class methods.
Here we are getting the db result array and based on the check(ACTIVE/INACTIVE) we are returning the boolean value.Instead of that we can have that check in the query itself like below
SELECT IF(status='ACTIVE',1,0) AS statuscheck from table1
Note that in the condition we need to give single equal symbol
so the code return ($result['status']=='ACTIVE')?1:0 will be replaced by return $result['statuscheck'].
Suppose we have the field in the table lets say status which has the ENUM value ACTIVE,INACTIVE.Usually after getting the value of this field(through the query)
we used to write return ($result['status']=='ACTIVE')?
Here we are getting the db result array and based on the check(ACTIVE/INACTIVE) we are returning the boolean value.Instead of that we can have that check in the query itself like below
SELECT IF(status='ACTIVE',1,0) AS statuscheck from table1
Note that in the condition we need to give single equal symbol
so the code return ($result['status']=='ACTIVE')?
Tuesday, December 16, 2008
Google Turns its Back on Firefox
About a month ago, Google dropped StarOffice from the Google Pack, a downloadable package of free Internet and productivity software for Windows users. StarOffice is a desktop office suite based on the open source OpenOffice.org program and distribute by Sun, and we theorized that Google was laying the ground work for a future push to get users to dump their desktop software in favor of Google’s own web-based application offerings.
For more details head over at http://www.sitepoint.com/blogs/2008/12/15/google-turns-its-back-on-firefox/
For more details head over at http://www.sitepoint.com/blogs/2008/12/15/google-turns-its-back-on-firefox/
Friday, December 12, 2008
CodeIgniter - Open source PHP web application framework
For more details check it in http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html
Subscribe to:
Posts (Atom)