doorman icon indicating copy to clipboard operation
doorman copied to clipboard

Does not work within classes

Open brtlbyx opened this issue 3 years ago • 1 comments

Hey,

I think I have a problem with this.

I want to include the script inside a backup class. However, I get - with two different calls - different results. Or rather none.

I have parsed the script several times within the last hours, but in the end the call within the class remains untouched, so I don't even get a logfile.

In the procedural call the process manager creates a logfile and also writes the content. In the object-oriented call, only the logfile is created - but remains without content.

Is it me?

OOP

use AsyncPHP\Doorman\Manager\ProcessManager;
use AsyncPHP\Doorman\Task\ProcessCallbackTask;
 
class myTaskTest {
	function __construct() {
		$this->manager = new ProcessManager();
		$this->manager->setLogPath("core/logs/tasklogs");

	}

	public function testing() {
		$task3 = new ProcessCallbackTask(static function () {
			print "in task 3\n";
		});

		$this->manager->addTask($task3);

		while ($this->manager->tick()) {
			usleep(250);
		}			
		return;
	}
} 
 
$testTaskings = new myTaskTest();
$testTaskings->testing();


Has anyone else experienced this problem? What am I doing wrong?

brtlbyx avatar Jun 15 '21 20:06 brtlbyx

I found out that the procedural call serves the worker.php correctly:

object(AsyncPHP\Doorman\Task\ProcessCallbackTask)#3 (3) {
  ["id": "AsyncPHP\Doorman\Task\ProcessCallbackTask":private]=>
  NULL
  ["expiredAt": "AsyncPHP\Doorman\Task\ProcessCallbackTask":private]=> ["expiredAt": "AsyncPHP\Doorman\Task\ProcessCallbackTask":private]
  NULL
  ["**closure**": "AsyncPHP\Doorman\Task\CallbackTask":private]=> ["closure": "AsyncPHP\Doorman\Task\CallbackTask":private]=>
  object(Closure)#5 (0) {
  }
}
in Task 1

The object-oriented approach leads to the following result in worker.php:

object(AsyncPHP\Doorman\Task\ProcessCallbackTask)#3 (3) {
  ["id": "AsyncPHP\Doorman\Task\ProcessCallbackTask":private]=>
  
NULL
  ["expiredAt": "AsyncPHP\Doorman\Task\ProcessCallbackTask":private]=> ["expiredAt": "AsyncPHP\Doorman\Task\ProcessCallbackTask":private]
  NULL
  ["**closure**": "AsyncPHP\Doorman\Task\CallbackTask":private]=>
  NULL
}

The closure is NULL in the worker.php.

i've tried to change the closure call:

from

$task1 = new ProcessCallbackTask(function () {
	print "in task 1\n";
});

to

$task3 = new ProcessCallbackTask(\Closure::bind(function () {
	print " in task 3";
 }, $scope));

result is the same.

Any suggestions?

brtlbyx avatar Jun 16 '21 13:06 brtlbyx