wujunze
V2EX  ›  PHP

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

  •  
  •   wujunze · Jan 30, 2016 · 3287 views
    This topic created in 3762 days ago, the information mentioned may be changed or developed.

    如果要设置成只有 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 replies    2016-02-07 12:46:55 +08:00
    xujif
        1
    xujif  
       Jan 30, 2016 via iPhone
    有 curl multi
    ayoungman
        2
    ayoungman  
       Jan 30, 2016
    陈述句用问号、进程线程都搞不清的 PHP 选手
    wujunze
        3
    wujunze  
    OP
       Jan 30, 2016
    @ayoungman 呵呵
    extreme
        4
    extreme  
       Jan 30, 2016
    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
       Jan 31, 2016
    嗯 谢谢大家
    jhdxr
        6
    jhdxr  
       Feb 6, 2016
    @wujunze 我觉得 @ayoungman 说的蛮对的。。。结果你这态度。。。呵呵哒
    wujunze
        7
    wujunze  
    OP
       Feb 7, 2016 via Android
    @jhdxr 逗逼,你啥意思
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 75ms · UTC 09:39 · PVG 17:39 · LAX 02:39 · JFK 05:39
    ♥ Do have faith in what you're doing.