$a=new FileProcessing($path1);
$b=new FileProcessing($path2);
$a->doProcessFile();
$b->doProcessFile();
此代碼運行doProcessFile()
爲$a
然後在順序運行doProcessFile()
爲$b
。 我要爲$a
在平行與doProcessFile()
爲$b
,所以我可以在parralel處理不同的文件運行doProcessFile()
。 我可以在PHP中做到這一點?PHP平行類實例
正如我所看到的,PHP處理腳本只能按順序排列。現在我想知道是否可以在parralel中運行同一腳本的多個實例,運行腳本之間的區別是我在調用每個腳本時傳遞的參數。例如:php myscript.php [path1]
然後我用不同的參數第二次調用這個腳本。
編號PHP不是多線程語言。你唯一的辦法就是'exec()'或者其他的產生php的兩個SEPARATE實例,每個實例都有自己獨立的路徑。 –
http://stackoverflow.com/questions/14236296/asynchronous-function-call-in-php – castis
就像@MarcB提到的PHP不是多線程的。除了使用exec,你也可以看看像beanstalkD的解決方案http://kr.github.io/beanstalkd/ – tlenss