
As I’ve said before, it is good practice to close mysql connections after you have finished working with them.
The same idea applies to variables, especially large arrays holding user data for example. After you used a certain variable and you are sure you don’t need it anymore in your script, simply destroy it to free […]
In an attempt to make every piece of code reusable and nicely encapsulated in a function / class, you might in fact slow down the execution of a script. Each method and object call consumes memory - a lot. Basically think of what code you will actually reuse later in your application / in other […]
PHP has quite a lot of build-in, bundled functions that make your life easier - if used, of course :)
Anyway, since regex is quite a pain in the back for lots of programmers, here’s a good advice: use string-related functions to achieve what you need.
Here are some useful ones:
strncasecmp: Binary safe case-insensitive string comparison of […]
Problem
If you specify relative paths when you include a file, then you are wasting precious time. Doing so makes PHP resolve the OS path - that is, find the file, which is located relative to the file which requests it. This takes some time and slows down (well, not drastically, but if every bit matters, […]
Some 1 and a half year ago, when I was a beginner with PHP (not that now I am a professional or something, but still - I’ve improved a lot :) ), I know only few of the useful predefined functions available in php and I used to build my own snippets/functions to accomplish what […]
Pursuing to achieve the name of “the easiest to learn and use programming language”, PHP indeed makes your life easier by doing some thing for you. For example, you do not have to declare / define each variable you’ll use in your script - PHP creates them on-the-fly. While this speeds up the development […]
Here’s a quick one: use echo when you output content, since it is faster that print.
Why is that? print() is a function, in fact and therefore it takes more time to process it.
So unless you have to output formatted content (in which case you’d use sprintf(), for example), just use echo. It is faster […]
This one’s a no-brainer. It is obvious that every time you run a php script, the interpreter has to compile it, then spit out the html output and deliver it to the requester. If you cache the html files and serve them directly, without recompiling them every time a visitor requests them, you`ll improve the […]
You’re most likely using PHP in conjunction with a DBMS (database management system) - let’s say, MySQL.
If you’re like I used to be some time ago, you most likely forget to close the database connection you’ve opened some hundred lines above in your script.
Well, I’ve learned my lesson, so to say…and now I always close […]
When you write PHP scripts and test them locally, you probably set PHP to show all errors, for easier debugging.
But if, when you use them on a “live” server, you use the “@” operator to suppress errors, then take note of the following…
Problem
Error suppression in PHP is very slow
Get rid of all your error suppressing […]
Recent Comments