mardi 23 juin 2015

PHP MultiThreading file_get_contents doesn't work

I use PThreads (PHP 5.4), but function file_get_contents inside thread isn't working. There is some code:

    foreach ($images as $img)
        $stack[] = new HelloWorld($img);
    foreach ($stack as $thread)
        $thread -> start();

And Thread class code

class HelloWorld extends Thread {
public function __construct($world) {
   $this->attach = $world;
}
public function run() { 
    file_put_contents('images/tmp/'.$this->attach['big_image'], file_get_contents($this->attach['orig_url']));
}

Warning: file_put_contents(images/tmp/imagename.jpg): failed to open stream: No such file or directory in

How to solve this problem? When I use other function, unlike run(), It works correct, but multithreading doesn't work




Aucun commentaire:

Enregistrer un commentaire