silverstripe / doorman Goto Github PK
View Code? Open in Web Editor NEWChild process management
License: Other
Child process management
License: Other
I work in a php7.2 environment with Linux 16 and I am using Doorman to handle threads. The process adds the tasks well, however, once the "Tick" method is executed, the task is not executed and no process appears in the list of processes related to the created task. The task does not run. I do not know if it is a problem with the version of php or the operating system that I use since it also does not show any error when executing the code. Thank you.
We noticed that ProcessManager.php calls the array_column function which is not supported in PHP 5.3 - however your documentation states the 1.X branch supports PHP 5.3 and above.
Please update documentation or add support for 5.3.
Composer warns that:
Package jeremeamia/superclosure is abandoned, you should avoid using it. Use opis/closure instead.
In our application we don't use stdout.log as default log file. How do I override stdout.log?
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?
Hi cgPitt,
I reproduced your code with a little modif in foreach loop..
But had that my $manager->tick() always result false without PHP error..
Result true on single addTask..
Did I had something wrong here? I used php70 version.
use AsyncPHP\Doorman\Manager\ProcessManager;
use AsyncPHP\Doorman\Task\ProcessCallbackTask;
$manager = new ProcessManager();
foreach($jobs as $job){
$manager->addTask(new ProcessCallbackTask(function()use($job){
doingJob($job);
}));
}
$manager>addRule($rule);
echo $manager->tick();
Regards,
There is some ability to alter aspects of the shell command that is executed here:
https://github.com/asyncphp/doorman/blob/master/src/Manager/ProcessManager.php#L132
However, we have found a need to alter the command to tag the output and send it to syslog e.g:
"{$binary} {$worker} %s 2>&1 | logger -t sometag -s {$stderr} & echo $!"
With the current API we're unable to achieve this without taking a copy of the ProcessManager
class (as it is designated as final
).
It would be great to either be able to create a subclass ProcessManager
and make amendments or alter the command via an expanded API.
I want to send callback 5 seconds after process finish. How to add parameter like associated array, object or string to the Task
?
ProcessManager
is final class
which prevents extensibility. This is especially problematic if custom shell commands ned to be run.
Fixed in #29
Hi there,
When I run the composer require command, I get
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- jeremeamia/SuperClosure 1.0.0 requires nikic/php-parser dev-master -> no matching package found.
- Installation request for asyncphp/doorman ^1.2 -> satisfiable by asyncphp/doorman[1.2.0].
- Conclusion: remove nikic/php-parser v1.4.0
- Conclusion: don't install nikic/php-parser v1.4.0
- asyncphp/doorman 1.2.0 requires jeremeamia/superclosure ^1.0 -> satisfiable by jeremeamia/SuperClosure[1.0.0, 1.0.1, 1.0.2].
- jeremeamia/SuperClosure 1.0.1 requires nikic/php-parser ~0.9 -> satisfiable by nikic/php-parser[v0.9.0, v0.9.1, v0.9.2, v0.9.3, v0.9.4, v0.9.5].
- jeremeamia/SuperClosure 1.0.2 requires nikic/php-parser ~0.9 -> satisfiable by nikic/php-parser[v0.9.0, v0.9.1, v0.9.2, v0.9.3, v0.9.4, v0.9.5].
- Can only install one of: nikic/php-parser[v0.9.0, v1.4.0].
- Can only install one of: nikic/php-parser[v0.9.1, v1.4.0].
- Can only install one of: nikic/php-parser[v0.9.2, v1.4.0].
- Can only install one of: nikic/php-parser[v0.9.3, v1.4.0].
- Can only install one of: nikic/php-parser[v0.9.4, v1.4.0].
- Can only install one of: nikic/php-parser[v0.9.5, v1.4.0].
- Installation request for nikic/php-parser == 1.4.0.0 -> satisfiable by nikic/php-parser[v1.4.0].
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
Cheers!
I have some errors with this piece of code:
class A {
public function run($machine_name) {
echo $machine_name;
}
}
class B extends A {
public static function listen() {
$manager = new ProcessManager();
$A = new A();
foreach(self::get_devices() as $k => $machine) {
$task[$k] = new ProcessCallbackTask(function() use($k, $machine, $A) {
A->run($machine->name); // No way
$A->run($machine->name); // No way
});
$manager->addTask($task[$k]);
}
while($manager->tick()) {
usleep(250);
}
}
}
How to call A
class method from ProcessCallbackTask
in B
class?
I would like to process async commands on a set of online machines, taken from db
Thanks in advance
Because this is not a silverstripe module, potentially use the 'self' provision in the travis shared config which doesn't install silversripe recipe.
If the shared config isn't a good fit, then at least update to use recent versions of php in the build matrix
It seems it's somewhat unnecessarily slow running a few tasks in parallel from a larger pool. Take ~1000 ProcessCallbackTasks loaded into the manager, with a rule forcing at most 10 running in parallel (from 0 -> 100 processor load).
The 'tick' method will loop through all 1000 tasks and determine if the task can run. The first ten will be set off running and added to $this->running
, each of the 990 afterwards will not run since there are ten processes running already. In each of those 990 cases though, it will perform the moderately expensive task of creating a Profile for each of the ten running processes. The profile will set the number of running processes at ten even if the process is not still running.
Only once looping through all 990, will it then remove non-running processes from the pool, and allow further processes to run, but this again allows 10 processes to run before needlessly looping through 980 more.
Am I right in my thinking here? It seems to me, that the only change necessary is to attempt to remove non-running processes from the running list at an earlier date. It feels like there may be a solution already to my use-case though that I'm not aware of.
If not, then I'd be happy to look deeper into this and contribute some form of fix/new feature, though.
I also think I may be slightly abusing the processor load functionality!
I really love your idea's, but it's pretty hard to get hold of it. Maybe a commented example program(s) will do some good, providing answers to the following questions:
`
<?php
use AsyncPHP\Doorman\Manager\ProcessManager;
use AsyncPHP\Doorman\Task\ProcessCallbackTask;
use AsyncPHP\Remit\Client\ZeroMqClient;
use AsyncPHP\Remit\Server\ZeroMqServer;
use AsyncPHP\Remit\Location\InMemoryLocation;
class Localtest extends CI_Controller {
public function index() {
try {
$numTasks = 10;
$manager = new ProcessManager();
echo("\ncreated manager");
$server = new ZeroMqServer(
new InMemoryLocation("127.0.0.1", 5555)
);
echo("\ncreated server");
$server->addListener("message-from-child-process", function ($message) {
echo("\nmessage from child process: {$message}");
});
echo("\nadded listener");
for ($i = 0; $i < $numTasks; $i++) {
if ($task = $this->getNextTask()) {
$manager->addTask($task);
echo("\nadded task");
}
}
while ($manager->tick()) {
echo("\nlistening");
$server->tick();
usleep(250);
}
} catch (Error $e) {
echo($e->getMessage());
} catch (Exception $e) {
echo($e->getMessage());
}
}
private function getNextTask() {
try {
$task = new ProcessCallbackTask(function () {
echo("\nin child");
$client = new ZeroMqClient(
new InMemoryLocation("127.0.0.1", 5555)
);
$data = "hello man";
$client->emit(
"message-from-child-process", [$data]
);
});
return $task;
} catch (Error $e) {
echo($e->getMessage());
} catch (Exception $e) {
echo($e->getMessage());
}
}
}
`
Expected output: Seeing the data (the string "hello man") 10 times, for 10 tasks.
Actual output:
created manager
created server
added listener
added task
added task
added task
added task
added task
added task
added task
added task
added task
added task
listening
listening
message from child process: hello man
So I see the output just once, instead of 10 times. Could you please help me understand what's going wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.