2010-04-24 93 views
0

基本上,我正在使用Apache Bench進行一些測試。我測試的文件需要2秒才能執行(其優化,它連接到外部服務器,因此減速)PHP啓動同時執行文件

基本上我發現,我模擬的併發用途越多,我可以執行的文件執行次數越多。

是否有無論如何,我可以做這樣的事情在PHP? :

<?php 

execute_file('file.php'); 
execute_file('file.php'); 
execute_file('file.php'); 
execute_file('file.php'); 
execute_file('file.php'); 

?> 

將會執行這個文件的5倍,但不會等待文件完成下載,那麼上面的例子將迅速調用5個函數,然後退出。

我假設一些超時會被使用?

回答

0

也許是這樣的?

function execute_file($file) { 
    $pid = pcntl_fork(); 
    if ($pid === 0) { 
     exec("php $file"); 
    } 
} 
0

怎麼樣?

exec('file.php'); 
+0

不適合我,腳本只是掛起時,我打電話exec – Ozzy 2010-04-24 09:56:14

0

exec('file.php');