如果要设置成只有 10 个进程来处理$urls 数组,应该怎么做?
<?php
header("Content-Type: text/html;charset=utf-8");
class DuoXianCheng extends Thread {
public function __construct($arg){
$this->arg = $arg;
}
public function run(){
if($this->arg){
// echo $this->result = $this->arg;
$this->result = model_http_curl_get($this->arg);
}
}
}
$thread = new DuoXianCheng("World");
if($thread->start()){
$thread->join();
}
function model_http_curl_get($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)');
$result = curl_exec($curl);
1
xujif 2016-01-30 02:42:52 +08:00 via iPhone
有 curl multi
|
2
ayoungman 2016-01-30 03:19:56 +08:00
陈述句用问号、进程线程都搞不清的 PHP 选手
|
4
extreme 2016-01-30 13:19:25 +08:00
Thread 类是线程,不是进程。
创建十个 DuoXianCheng 的对象: for ($i = 0 ; $i <=9 ; $i++) { $obj[$i] = new DuoXianCheng("World"); $obj[$i]->start(); } http://yzs.me/2535.html |
5
wujunze OP 嗯 谢谢大家
|