Benchmark: dirname(__FILE__) vs __DIR__ in PHP

dirname(__FILE__) and __DIR__ give exactly the same result in PHP, although one (__DIR__) is evaluated at compile-time, while the other (dirname(__FILE__)) has at least part of it (the function) evaluated at execution time. Ever wondered what the difference is, in terms of efficiency, between the two? I've written a *very* simple script to try it out:
$loops = 100000000;
echo 'Testing dirname(__FILE__)' . PHP_EOL;
$start = time();
$dir = '';
for ($i = 0; $i < $loops; $i++) {
 $dir = dirname(__FILE__);
echo 'dirname(__FILE__) took ' . (time()-$start) . 's' .

Can't use function return value in write context

Did you ever develop some nice code, then simply wanted to check if a string was only composed of white spaces or tabs, and used something like this:
if (!empty(trim($string))) { ... }
...only to get a bad error appear (only on your PHP 5.4 server) in the middle of your app, like this?:
Fatal error: Can't use function return value in write context
Well, this has a simple explanation... Prior to PHP 5.5, the empty() function did not accept something else than a variable.

Using php5-memcached to store sessions on distributed servers

This article is an extension of the previous article about storing sessions in Memcached with PHP. Using Memcached for sessions storage is generally a matter of speed (storing them in memory is faster than on disk) and of scalability (using a Memcached server allows you to have several web servers serving the same PHP application in a seamless way). In the previous article, we mentioned (3 years ago) that the php5-memcached extension did not seem to manage the storage of sessions quite well, or at least t

Howto: Configuring session expiry time in Chamilo

Note: this article was originally written for Chamilo 1.9 but it is also valid for all versions 1.10 and 1.11. We seldom receive a request from users of Chamilo LMS saying their sessions are cut in the middle of their activity. And sure, it might so happen that you are in the middle of the redaction of a very large answer to an open question, or diserting on how the course is going to help you in the forum. And we get that it's super-frustrating to click "submit" and then get an error page.

Creating new tasks in chamilo course-sessions

In the category of little scripts that can make your life easier when managing huge Chamilo portals, this is a little one that creates one tasks-folder called "ALP" for the "Assignments" (work) tool in each active course for a portal where you have thousands of sessions, with one course per session. The script works for version 1.9.8 of Chamilo, but might need some adaptations to run on an older version, in particular considering the addDir() function from the main/work/work.lib.php library which was created there recently. You should put the file into any "one-level" directory under the Cha

On PHP and cache slams and solutions

While reading about Doctrine's cache mechanism (which applies to other stuff than database queries, by the way), my eye was caught by a little message at the end (last section) about cache slams. I have used cache mechanisms extensively over the last few years, but (maybe luckily) never happened to witness a "cache slam". There's a link to a blog (by an unnamed author) that explains that. To make it short, you can have race conditions in APC (and

PHP's @ hurts performance

Did you know...? As a "take away" information taken from this post (by famous PHP core developer @nikita_ppv), it appears like the @ sign in PHP (used to "hide" errors, as the "error-suppression operator" it is) also disables the "compiled variables" optimization (OpCode caching).

Gallery 2.3 not translating

Just in case you would fall upon this issue as well, Gallery2 requires the corresponding language-specific locales to be installed on the system (it depends on them to show the matching translated terms). The code to do that (and to debug it) is located (in Gallery 2.3) on line 330 of modules/core/classs/GalleryTranslator.class. We hope it helps you a little.

PHP's call_user_func_array() is slow

I just solved an issue that had me waking up in the middle of the night for weeks (just pushing it a bit) and I have to thank PHP's community and in particular a guy named Brad Proctor for writing a very short but very important comment in the PHP manual, and I quote:
This function is relatively slow (as of PHP 5.3.3) and if you are calling a method with a known number of parameters it is much faster to call it this way: $class->{$method}($param1, $param2);
He mentions