php - Running code parallel with ReactPhp -


problem: need clone/download several git repositories, unfortunately doing sequentially takes ages. got idea use reactphp event loop , parallelly.

despite of many attempts not able running parallelly. maybe misunderstood concept, expectation reactphp somehow fork execution of code.

could take @ code , share guidelines how working?

use symfony\component\stopwatch\stopwatch;  include 'vendor/autoload.php';  $toclone = [     ['url' => 'http://github.com/symfony/symfony.git', 'dest' => 'c:\tmp\cloner1'],     ['url' => 'http://github.com/laravel/laravel.git', 'dest' => 'c:\tmp\cloner2'],     ['url' => 'http://github.com/rails/rails.git', 'dest' => 'c:\tmp\cloner3'], ]; $end = count($toclone); $i = 0;  $deferred = new react\promise\deferred(); $fclone = function (\react\eventloop\timer\timer $timer) use (&$i, $deferred, &$toclone, $end) {     $project = array_pop($toclone);     $git = new \gitwrapper\gitwrapper();     $git->settimeout(3600);     $git->clonerepository($project['url'], $project['dest']);     $deferred->notify([$i++, $project['url']]);     if ($end <= $i) {         $timer->cancel();         $deferred->resolve();     } };  $stopwatch = new stopwatch(); $stopwatch->start('run');  $loop = react\eventloop\factory::create(); $loop->addperiodictimer(1, $fclone);  $deferred->promise()->then(function () use ($stopwatch) {     echo 'done' . php_eol;     $event = $stopwatch->stop('run');     echo 'run took ' . $event->getduration() / 1000 . 'sec , ' . $event->getmemory() . ' bytes of memory'; }, null, function ($data) {     echo 'run ' . $data[0] . ' - ' . $data[1] . php_eol; });   $loop->run(); 

my composer.json

{     "require": {         "react/promise": "2.2.0",         "react/event-loop": "0.4.1",         "cpliakas/git-wrapper": "1.4.1",         "symfony/stopwatch": "2.7.0"     } } 

os: windows7 php: 5.4.8 , 5.5.20
none of these enxtensiosn installed

"suggest": {     "ext-libevent": ">=0.1.0",     "ext-event": "~1.0",     "ext-libev": "*" }, 

so streamselectloop used

the primary issue you're dealing $git->clonerepository() call blocking; reactphp allows dealing application level loops. if don't make code non-blocking, code still operate in linear way. have suss out how clone happen in background; done forking process or calling php script run in background. unsure of git wrapper operates this, if can find library git calls in non-blocking way; issue mostly resolved.

reactphp doesn't turn php non-blocking, provides framework allow non-blocking techniques. if code blocks, react loop not run.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -