V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wujunze
V2EX  ›  PHP

求助, php 使用 Pthread 进行多进程的问题?

  •  
  •   wujunze · 2016-01-30 01:33:28 +08:00 · 2624 次点击
    这是一个创建于 3018 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如果要设置成只有 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);
    
    7 条回复    2016-02-07 12:46:55 +08:00
    xujif
        1
    xujif  
       2016-01-30 02:42:52 +08:00 via iPhone
    有 curl multi
    ayoungman
        2
    ayoungman  
       2016-01-30 03:19:56 +08:00
    陈述句用问号、进程线程都搞不清的 PHP 选手
    wujunze
        3
    wujunze  
    OP
       2016-01-30 10:36:49 +08:00
    @ayoungman 呵呵
    extreme
        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
    wujunze
        5
    wujunze  
    OP
       2016-01-31 09:04:10 +08:00
    嗯 谢谢大家
    jhdxr
        6
    jhdxr  
       2016-02-06 15:22:32 +08:00
    @wujunze 我觉得 @ayoungman 说的蛮对的。。。结果你这态度。。。呵呵哒
    wujunze
        7
    wujunze  
    OP
       2016-02-07 12:46:55 +08:00 via Android
    @jhdxr 逗逼,你啥意思
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2604 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 651ms · UTC 09:06 · PVG 17:06 · LAX 02:06 · JFK 05:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.