multithreading, pthreads.
-, . PHP , .
man- flock
flock() ; , flock() / .
, , cron , ... .
( pthreads) , pthreads API .
, :
<?php
class Test extends Thread {
public function __construct(Threaded $monitor) {
$this->monitor = $monitor;
}
public function run () {
$this->monitor->synchronized(function(){
for ($i = 0; $i < 1000; $i++)
printf("%s #%lu: %d\n",
__CLASS__, $this->getThreadId(), $i);
});
}
private $monitor;
}
$threads = [];
$monitor = new Threaded();
for ($i = 0; $i < 8; $i++) {
$threads[$i] = new Test($monitor);
$threads[$i]->start();
}
foreach ($threads as $thread)
$thread->join();
$monitor
, , Threaded
, , :
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
Test
<-- snip for brevity -->
Test
, Thread
Closure
, Threaded::synchronized
.