PHP - 访问相同资源的多个脚本实例

I have to analyze a lot of information. To speed things up I'll be running multiple instances of same script at the same moment.

However there is a big chance scripts would analyze same piece of information(duplicate) which I do not like as it would slow down the process.

If running only 1 instance I solve this problem with array(I save what has been already analyzed).

So I have a question how could I somehow sync that array with other "threads" ?

MySQL is an option but I guess it would be overkill? I read also about memory sharing but not sure if this is solution I am looking for.

So if anyone has some suggestions let me know.

Regards

This is a trivial task using real multi-threading:

<?php
/* we want logs to be readable so we are creating a mutex for output */
define ("LOG", Mutex::create());
/* basically a thread safe printf */
function slog($message, $format = null) {
    $format = func_get_args();
    if ($format) {
        $message = array_shift($format);

        if ($message) {
            Mutex::lock(LOG);
            echo vsprintf(
                $message, $format);
            Mutex::unlock(LOG);
        }
    }
}

/* any pthreads descendant would do */
class S extends Stackable {
    public function run(){}
}

/* a thread that manipulates the shared data until it's all gone */
class T extends Thread {
    public function __construct($shared) {
        $this->shared = $shared;
    }
    public function run() {
        /* you could also use ::chunk if you wanted to bite off a bit more work */
        while (($next = $this->shared->shift())) {
            slog(
                "%lu working with item #%d
", $this->getThreadId(), $next);
        }
    }
}

$shared = new S();
/* fill with dummy data */
while (@$o++ < 10000) {
    $shared[]=$o;
}

/* start some threads */
$threads = array();
while (@$thread++ < 5) {
    $threads[$thread] = new T($shared);
    $threads[$thread]->start();
}

/* join all threads */
foreach ($threads as $thread)
    $thread->join();

/* important; ::destroy what you ::create */
Mutex::destroy(LOG);
?>

The slog() function isn't necessarily required for your use case, but thought it useful to show an executable example with readable output.

The main gist of it is that multiple threads need only a reference to a common set of data to manipulate that data ...