kriswallsmith / spork
异步PHP
v0.3
2015-05-18 19:16 UTC
Requires
- php: >=5.3.0
- ext-pcntl: *
- ext-posix: *
- ext-shmop: *
- symfony/event-dispatcher: *
This package is auto-updated.
Last update: 2024-08-29 03:20:54 UTC
README
Spork: PHP在分支上运行
<?php $manager = new Spork\ProcessManager(); $manager->fork(function() { // do something in another process! return 'Hello from '.getmypid(); })->then(function(Spork\Fork $fork) { // do something in the parent process when it's done! echo "{$fork->getPid()} says '{$fork->getResult()}'\n"; });
示例:上传图片到您的CDN
将迭代器输入进程管理器,它将工作分解成多个批次并在许多进程中分配。
<?php $files = new RecursiveDirectoryIterator('/path/to/images'); $files = new RecursiveIteratorIterator($files); $manager->process($files, function(SplFileInfo $file) { // upload this file });