How to include my "getDetails" function which takes a value (here a variable: "$href") as a parameter in Worker\enqueueCallable ???
chegmarco1989 opened this issue · 2 comments
Hello.
We are trying to use this amPHP-Parallel library (https://github.com/amphp/parallel) to our getDetails($href)
function. Knowing that the README used the file_get_contents
function in the promises as follows:
$urls = [
'https://secure.php.net',
'https://amphp.org',
'https://github.com',
];
$promises = [];
foreach ($urls as $url) {
$promises[$url] = Worker\enqueueCallable('file_get_contents', $url);
}
$responses = Promise\wait(Promise\all($promises));
foreach ($responses as $url => $response) {
\printf("Read %d bytes from %s\n", \strlen($response), $url);
}
While my getDetails($href)
function, which I am trying to process in parallel, as you can see, takes as a parameter or argument between brackets, a value (here represented by the variable $href
), how then, can I include it in the Worker\enqueueCallable()
to replace the default file_get_contents
???
Please enlighten me please.
Apologies that this issue did not receive more immediate attention.
To use a function in a worker pool, you must define the function in a way that the Composer autoloader can load. In general, I'd recommend exploring the Task
interface instead to define custom logic to execute in a worker.
Seeing as this issue is old, I'm going to close it. If you need further support, please open another issue (and I'll try to reply a bit faster) 👍
Could you give me a usage example for my getDetails($href)
function ???
Please guide me.
Awaiting your reply.