PHP code example of lisao / process
1. Go to this page and download the library: Download lisao/process library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lisao / process example snippets
$app = new \Lisao\Process\Process([
'process_count' => 4 , //运行的线程数
'process_save' => './process.pid' //线程 id 保存路径,用于停止进程时使用
]);
/*
* $work_id 为工作id,从0开始,根据线程数顺序递增。
* 用于区分进程,指派任务
*/
$app->start(function($work_id){
echo "我启动了,工作ID:{$work_id} \n";
});
class obj {
public function test($work_id) {
echo "我启动了,工作ID:{$work_id} \n";
}
}
$obj = new obj();
$app->start($obj, 'test');
$app->stop();