note 48123 deleted from function.serialize by aharvey
| From: | aharvey@php.net | Date: | Tue, 06 Nov 2012 02:07:02 +0000 |
| Subject: | note 48123 deleted from function.serialize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191755@lists.php.net to get a copy of this message | ||
Note Submitter: richard dot prangnell at ntlworld dot com
----
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.