You can try something like this...

<? php
$i = 0;
while($table[$i]) {
    if(preg_match('/@/', $table[$i]) {
        // do email process 

    } else if (preg_match('/http:\/\//', $table[$i]) {
        // do url process

    } else {
        throw new exception ('Unrecognized table entry');

I am developiong a php application which builds several large collections of objects in the course of interacting with the user. The objects need to persist across requests from the user and I've used php sessions to successfully implement this. The objects are persisted until the user is satisfied with what they have done and they request the information represented by the objects to be saved.

In profiling the application I found that the session start takes about half of the total time of a request (about 4 seconds in total for a request). Since not all stored objects are used on each request from the user, I attempted to improve the responsiveness of the application by selectively restoring the objects needed for the request. To do this I have serialized the objects to individual files and only unserialized those required. This change actually blew up the application because the serialize/unserialize consumed huge amounts of memory (and time to run). It surprised me that the session handler could serialize and unserialize all of the objects in less time and lower memory consumption than my attempt to do only a subset. I believe this may be due to the loading of all the serialized object data into memory, but I'm not sure.

Following is the code to serialize and unserialize the objects that I have used:

Code to write the serialized object to files:

public static function writeClose() {
    foreach (self::$activeRegistries as $registryName=>$registry) {
        if (isset($_SESSION["filemap"]) && isset($_SESSION["filemap"]["registries"]) && isset($_SESSION["filemap"]["registries"][$registryName])) { ...