note 48123 added to function.serialize

From: Date: Sun, 12 Dec 2004 22:08:17 +0000
Subject: note 48123 added to function.serialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-81734@lists.php.net to get a copy of this message
Although the serialise function has its proper uses, it is a relatively slow process. I try to avoid using it wherever possible in the interests of performance. You can store text records in a database as plain text even when it contains PHP variables. The variable values are lost, naturally; but if they can easily be re-attached to retrieved records, zillions of clock cycles can be saved simply by using the str_replace() function: if($convert) { $mainContent = str_replace('$fixPath', $fixPath, $mainContent); $mainContent = str_replace('$theme', $theme, $mainContent); } The above snippet is used in a CMS project. $fixPath contains something like '.' or '..' to prepend relative paths (allowing the record to be used by scripts located in different parts of the directory hierarchy) and $theme inserts the name of the users custom page rendering scheme, which obviously would be undefined at record storage time anyway. ---- Manual Page -- http://www.php.net/manual/en/function.serialize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48123 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48123&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48123&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48123&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48123&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48123&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48123&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48123&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81734) next »