2015-04-28 3 views
0

после начала моей нитьКак отделить нить в PHP

$dnld = new download($arr[$i]); 
$dnld->start(); 

Я попытался снять эту нить с помощью

$dnld->detach(); 

Я получаю ошибку

Вызов к неопределенному методу загрузки: : отделить()

хотя я присоединиться() точно так же без проблем

$dnld->join(); 

это моя нить класс

class download extends Thread { 
    public $url; 
    public $sz; 
    public $type; 
    public $results; 

    public function __construct($s){ 
     $this->url = $s['1']; 
     $this->sz = $s['2']; 
     $this->type = $s['3']; 
    } 

    public function run() { 
     try{ 
       set_time_limit(0);         // prevent apache server from timing out while downloading large files 
       $id = md5($this->url);       // create a unique ID for each file (prevent over-write) 
       $tmp = __DIR__ ."\\downloads\\{$id}";    // storage location 
       $fp = fopen ($tmp, 'w+');      // open file for writing 
       $ch = curl_init(str_replace(" ","%20",$this->url));     // download file 
       curl_setopt($ch, CURLOPT_TIMEOUT, 0);   // request timeout -> never 
       curl_setopt($ch, CURLOPT_FILE, $fp);   // file to write to 
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
       curl_exec($ch);         // start download 
       curl_close($ch);        // download complete 
       fclose($fp);         // close file 
       if(($this->sz < (1024*1024*128))&&($this->type == 1)){ 
        require('virusTotal.php'); 
        $res['type'] = 'virusTotal'; 
        $res['res'] = scanFiles($tmp,$this->url);  // send file to scanners 
       }else{ 
        require('scanner.php'); 
        $res['type'] = 'localScan'; 
        $res['res'] = scanFiles($tmp);  // send file to scanners 
       } 

       $this->results = array('result'=>'SUCCESS', 'msg'=>$res); 
     }catch(Exception $e){ 
      $this->results = array('result'=>'FAILED', 'msg'=>$e);   // return error code 
     } 
    } 
} 

ответ

1

Подробнее: http://php.net/manual/en/thread.detach.php

Предупреждение

Этот метод может вызвать неопределенное, небезопасное поведение. Он не должен использоваться, как правило, , он присутствует для полноты и расширенного использования .

+0

есть ли другой способ, позволяющий основному процессу выйти, не дожидаясь завершения потоков? –

+0

http://stackoverflow.com/questions/2585656/threads-in-php И http://stackoverflow.com/questions/858883/run-php-task-asynchronously – Kristiyan