Archiv der Kategorie ‘PHP‘


PHP: Deprecated session_is_registered and session_unregister

Today i found in a older website i administrate some messages in the Apache error logfiles.

They looked like this:

PHP Deprecated: Function session_is_registered() is deprecated
PHP Deprecated: Function session_unregister() is deprecated

I searched the web and found this replacement code:

array_key_exists($variable, $_SESSION);



I hope this might help someone.

Do not use isset() here, because it might be wrong!
PHP - Benchmark isset() or array_key_exists() ?

PHP: Micro vs. Macro optimization, or "Get the low hanging fruit first"

After using and developing PHP for a few years now, i heard pretty much stuff about optimization, special technice's and other myths and fairy tales. But this article is not about tips or tricks, it is about if this the real key to better performance.

Den ganzen Beitrag lesen...

PHP: Easy and secure password hashing class

Everybody talks about security but most of the people still save md5(password) in their databases. This is not funny. Reversing a simple and even a average password is not that hard.
I once wrote this tiny class that generates secure enough password hashes.

Den ganzen Beitrag lesen...

PHP: FIFO queue with APC

A few days ago i needed a simple queue class that would also be persistent after the pagerequest. I first thought about putting this queue in SQL but did not want the whole SQL overhead and such and remembered a blog artice about memcache queues a once read. But i had no memcache for that project and used APC instead.

Den ganzen Beitrag lesen...

PHP/MySQL: Warning: mysql_query(): Unable to save result set ...

Today i found a error in a tiny script i was working on.
The error Message looked like this:

Warning: mysql_query() [function.mysql-query]: Unable to save result set in /var/www/example.php on line 55

First i found a few hints about repairing or optimizing MySQL tables, but this did not work out.
After a few debugging outputs a realized that the query was not properly written.

Den ganzen Beitrag lesen...

PHP: phpMyAdmin3 - deactivate slider effects

For all of you who liked phpMyAdmin2 where all relevant information was visible at any time, sould be annoyed be the new slider effects in phpMyAdmin3.
I did a short search for the config value to change this and found this solution.

Add this to your

// Change slider behaviour
$cfg['InitialSlidersState'] = 'open';

And your sliders will start in visible state.

phpMyAdmin download:

PHP: floor() and ceil() are slow!

A workmate mentioned, that floor($i) could be replaced with (int)$i.
I found this very interresting and did some researched about that.

floor($i); will return a float that will have the lower value of $i.
A cast will just convert $i to an integer which will cut of all decimals.
So by symptoms, these two methods are equivalent. Even if floor returns a float, PHP does dynamic casting of its variables.

Den ganzen Beitrag lesen...

PHP: Do NOT rebuild preg_* functions!

In a PHP Project i am currently helping out, i found this function:

 * Replaces every char in $str that does is not in $valid array
 * @param array $valid
 * @param string $str
 * @return string

function cleanString($valid, $str) {
  $ret = '';
  $len = strlen($str);
  for($i = 0; $i < $len; ++$i) {
    if(in_array($str[$i], $valid, true)) {
      $ret .= $str[$i];
  return $ret;

It is a simple function for replacing chars. It works quite well, but was mainly only used for checking [^a-z0-9]. So i tested the speed of this code.

Den ganzen Beitrag lesen...

PHP: Easy Memcache handling

In a current project of mine i needed the use of a universal caching system.
After testing a little bit with APC i found memcache that will do the job perfectly.
So i wrote a few tiny functions for easy memcache handling.

Den ganzen Beitrag lesen...

PHP: String Flipper Class (Rewrite)

I found this class on Twitter. Nice idea flipping chars by replacing them with their unicode upside down alternative.
But what bugged me was the code, it looked awful. So id did a rewrite to clean it up a little bit.

Den ganzen Beitrag lesen...