2014-12-22 38 views
0

我想運行3 不同的一次性的簡單腳本,每個腳本都會抓取網站內容並返回一個字符串。哪個pcntl,pthreads,後臺exec()方法最適合?我最感興趣的是低資源消耗。運行並行PHP腳本的最佳方法

回答

0

一般很難回答。

你想優化哪個資源?

反正第一個例子在這裏回答你的問題主要是:http://php.net/manual/en/function.pcntl-fork.php

<?php 
for ($i = 1; $i <= 5; ++$i) { 
     $pid = pcntl_fork(); 

     if (!$pid) { 
      sleep(1); 
      print "In child $i\n"; 
      exit($i); 
     } 
    } 

    while (pcntl_waitpid(0, $status) != -1) { 
     $status = pcntl_wexitstatus($status); 
     echo "Child $status completed\n"; 
    } 
?> 
+0

我的意思是由resousrce分配的RAM。如果我理解得很好,pcntl_fork用於在多個實例中運行相同的進程/腳本,對吧?我最好在我的Q中加入「不同」一詞。 – user965748

0

因爲我發現我的主機不提供擴展的EXEC方式是去的唯一的一個。然而pthreads似乎是最有效的。