Вопрос

I'm running the scripts in windows through the browser using WAMP but it seems to crash the Apache HTTP Server. When the code is executed in the command line I get a: "CLI has stopped working" error and a "Fault Module Name: pthreadVC2.dll"

AFTER SERVER UPDATE, NOW INSTALLED:

Wamp version 2.5

Apache version 2.4.9

PHP version 5.5.12

Compiler VC11

UPDATE: The basic Hello World script runs fine, showing that standard threading works as expected but not stacking with a Worker.

The Hello World Script (which runs fine):

<?php
class AsyncOperation extends Thread {
  public function __construct($arg){
    $this->arg = $arg;
  }

  public function run(){
    if($this->arg){
      printf("Hello %s\n", $this->arg);
    }
  }
}
$thread = new AsyncOperation("World");
if($thread->start())
  $thread->join();
?>

This prints "Hello World" both in the command line and in the browser.

Running this script though crashes:

<?php
class Work extends Stackable
{
    public function run ()
    {
        echo "test"
    }
}

$my = new Worker();
$work = new Work();

$my->start();
$my->stack($work);
?>

Any ideas?

Thanks

Это было полезно?

Решение

What is happening here

Explicable and avoidable ...

https://gist.github.com/krakjoe/6437782

So we do not do the done thing; in a pthreads application, you are responsible for the objects you create, you are also responsible for retaining a reference to objects that are going to be executed, or accessed from other executing contexts, until that execution or access has taken place.

This applies as much to shutdown time as it does to runtime, what is happening here is that Zend is shutting down and destroying the Work variable before it is executed, even though you retain a reference.

You must force the worker to synchronize with the current thread by joining with it, Worker::shutdown will solve the problem.

<?php
class Work extends Stackable
{
    public function run ()
    {
        echo "test"
    }
}

$my = new Worker();
$work = new Work();

$my->start();
$my->stack($work);
$my->shutdown();
?>

Другие советы

If I remember correctly Apache 2.2.12 was compile/linked with VC6, I can only find the php_pthread extension compiled with VC9 and VC11.

As Apache was compiled with VC6 it is safe to assume that PHP5.4.3 was also compiled with VC6 as these 2 have to be compiled with the same environment to run in a wampserver configuration.

If you downloaded either one of these (VC9 or VC11) these extension will not run in your current configuration.

Either you will have to find a php_pthread extension compiled with VC6 or upgrade your Apache and PHP to a compatible version.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top