PHP is probably one of the most widely used open source general-purpose scripting languages on the web. It is used to enhance web pages. With PHP, you can do things like create user id and password login web pages, check details from a form, create forums, blog, picture galleries, and a lot more. If the URL of the web page ends with .php, then the author has written some programming code to liven up the plain, old HTML.
- PHP stands for Hypertext Preprocessor
- PHP scripts are executed on the server
- PHP supports many databases like MySQL, Oracle, Sybase, PostgreSQL, Generic ODBC, etc.
- PHP is open source software
- PHP is free to use and download
15 PHP Web Development Tips and Tricks
PHP is most likely the preferred web development languages in the world. There are already over 20 million domains on the web that have made use of PHP Web Development techniques.
I have read about many of these points in books and online tutorials. Initially I ignored it but after that I realized its importance for security with PHP & MySQL, but I would like to suggest everyone who is new to PHP is to read these tips and apply them before you end up with a big confusion.
1. Echo() versus print():
Echo is quicker than print. Both functions are used for the same thing but echo is the language constructs which return nothing, which publish will return 0 or 1 based on success or failure.
2. Be sure to validate user input on the server side:
3. Use single quotes for longer strings rather than double quotes
Because in double quotes it will search for PHP variable to evaluate them. So in this case, in single quotes is faster because it does not require any string manipulation.
4. Always escape the output:
It will avoid XSS (Cross Site Scripting) attacks. You have to be sure about it i.e., When displaying user input on a page use htmlentities($user_bio, ENT_QUOTES, ‘UTF-8′).
5. If you have declared a method as static then let it is the same, as its 33% quicker than member functions.
6. Try to use minimize relative paths:
For relative path insertion it will search for default include path then current directory then so on. As a result file search in that case may catch more time.
7. Identical operator (===) is faster than (==) operator as identical operator will include type checking also.
8. Avoid using short tags and try to use , It can generate a problem for you if you are available to organize your application on another server.
9.Echo’s multiple parameters:
For faster result, use echo's multiple parameters instead of string concatenation.
10. Specify full paths:
Try to use full paths in includes and requires, for less time spend on resolving the OS paths.
11. Derived classes vs. base classes:
You may have to know i.e., methods in derived classes run faster than ones defined in the base class.
12. About accessing arrays:
e.g. $row['id'] is 7 times faster than $row[id]
13. Do not implement every data structure as a class:
Avoid to being everything OOP, as often it is too much overhead, and each method and object call consumes more memory. For this case, do not implement every data structure as a class, arrays are useful, too.
14. Avoid functions inside loops:
Try to use functions outside loops. If not the function may get called each time.
15. Free unnecessary memory:
Unset your variables to free memory, especially large arrays.