Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work within classes #39

Open
brtlbyx opened this issue Jun 15, 2021 · 1 comment
Open

Does not work within classes #39

brtlbyx opened this issue Jun 15, 2021 · 1 comment

Comments

@brtlbyx
Copy link

brtlbyx commented Jun 15, 2021

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
Copy link
Author

brtlbyx commented Jun 16, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant