simple-fork-php icon indicating copy to clipboard operation
simple-fork-php copied to clipboard

Uncaught RuntimeException: you should extend the `\Jenner\SimpleFork\Process` and overwrite the run method

Open shtse8 opened this issue 8 years ago • 6 comments

According to the example:

$pool = new \Jenner\SimpleFork\FixedPool(2);
$pool->execute(new \Jenner\SimpleFork\Process(new TestRunnable()));
$pool->execute(new \Jenner\SimpleFork\Process(new TestRunnable()));
$pool->execute(new \Jenner\SimpleFork\Process(new TestRunnable()));

$pool->wait();

Code:

use \Jenner\SimpleFork\Pool;
use \Jenner\SimpleFork\FixedPool;
use \Jenner\SimpleFork\ParallelPool;
use \Jenner\SimpleFork\Process;
use \Jenner\SimpleFork\Runnable;

class TestRunnable implements Runnable 
{
	private $id = 0;

	public function __construct($id) {
		$this->id = $id;
	}
	
    public function run()
    {
		echo "[".$this->id."]\n";
		sleep(1);
    }
	
}

$pool = new FixedPool(2);
$pool->execute(new Process(new TestRunnable(1)));
$pool->execute(new Process(new TestRunnable(2)));
$pool->execute(new Process(new TestRunnable(3)));
$pool->wait();

Result:

PHP Fatal error:  Uncaught RuntimeException: you should extend the `\Jenner\SimpleFork\Process` and overwrite the run method in /var/www/site/www/core/vendor/jenner/simple_fork/src/Utils.php:31
Stack trace:
#0 /var/www/site/www/core/vendor/jenner/simple_fork/src/FixedPool.php(34): Jenner\SimpleFork\Utils::checkOverwriteRunMethod('Jenner\\SimpleFo...')
#1 /var/workspace/test_curl.php(31): Jenner\SimpleFork\FixedPool->execute(Object(Jenner\SimpleFork\Process))
#2 {main}
  thrown in /var/www/site/www/core/vendor/jenner/simple_fork/src/Utils.php on line 31

shtse8 avatar Mar 29 '17 17:03 shtse8

But it works with new Pool(), I assume they are the same but with different pool type.

shtse8 avatar Mar 29 '17 17:03 shtse8

It looks like a logical mistake, I will check it these days.

white-poto avatar Mar 31 '17 03:03 white-poto

I need to use FixedPool but it seems it is not working properly.

shtse8 avatar Apr 02 '17 15:04 shtse8

any news on this?

shtse8 avatar Apr 19 '17 07:04 shtse8

I am too busy recently, will check it after 5.1.

white-poto avatar Apr 21 '17 03:04 white-poto

I got the same problem here.

I think the point is

function checkOverwriteRunMethod

rainlay avatar May 09 '17 03:05 rainlay