spork, 分叉PHP实验库

分享于 

2分钟阅读

GitHub

  繁體 雙語
Experimental library for forking PHP
  • 源代码名称:spork
  • 源代码网址:http://www.github.com/kriswallsmith/spork
  • spork源代码文档
  • spork源代码下载
  • Git URL:
    git://www.github.com/kriswallsmith/spork.git
    Git Clone代码到本地:
    git clone http://www.github.com/kriswallsmith/spork
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/kriswallsmith/spork
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    Build Status

    Spork: fork 上的PHP

    
    
    
    
    <?php
    
    
    
    
    
    $manager = new SporkProcessManager();
    
    
    $manager->fork(function() {
    
    
     // do something in another process!
    
    
     return 'Hello from '.getmypid();
    
    
    })->then(function(SporkFork $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
    
    
    });
    
    
    
    

    for  EXP  PHP  FORK  Forking