【发布时间】:2015-04-23 19:06:24
【问题描述】:
当创建一个新的 PHP 子线程时,它变得无法使用 unlink() 删除文件。这种限制有充分的理由还是我忘记了什么? 我穿了:
警告:取消链接(下载/1e6f6fa1c0552a1af9058f10216b40e8):没有这样的 文件或目录
虽然文件是在目标文件夹中创建的,但当我在线程函数之外运行相同的命令时,它会按原样删除文件。
//多线程类
<?php
class download extends Thread {
public $i;
public $res;
public function __construct($s){
$this->i = $s;
}
public function run() {
try{
$url = "http://my.link.com/{$this->i}";
set_time_limit(0);
$id = md5(uniqid());
$tempName = md5($id.time());
$tmp = "downloads/{$tempName}";
$fp = fopen (dirname(__FILE__) . '/'.$tmp, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
require('scanner.php');
$results = scanfiles($tmp);
unlink($tmp);
$this->res = $results;
}catch(Exception $e){
$this->res = '0';
}}} ?>
【问题讨论】:
-
请包含您的代码
-
有一个很好的理由 - 即您在打开和取消链接的文件路径上犯了一个错误。为什么要混合相对路径和绝对路径?
标签: php multithreading