(PECL pthreads >= 2.0.9)
Threaded::from — Creation
This method has been removed in pthreads v3. With the introduction of anonymous classes in PHP 7, these can now be used instead.
Creates an anonymous Threaded object from closures
runThe closure to use for ::run
constructThe constructor to use for anonymous object
argsThe arguments to pass to constructor
A new anonymous Threaded object
Exemplo #1 Thread safe objects from closures
<?php
$pool = new Pool(4);
$pool->submit(Collectable::from(function(){
echo "Hello World";
$this->setGarbage();
}));
/* ... */
$pool->shutdown();
?>
O exemplo acima irá imprimir:
Hello World