fork-helper | A PHP helper to fork processes and allow multi-threading | Architecture library
kandi X-RAY | fork-helper Summary
kandi X-RAY | fork-helper Summary
A PHP helper to fork processes and allow multi-threading
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run a callable function
- Add an Exception to shared memory
- Get all exceptions .
- Wait for any thread
- Wait for process .
- Clean up the process .
- Get all PIDs .
fork-helper Key Features
fork-helper Examples and Code Snippets
Community Discussions
Trending Discussions on fork-helper
QUESTION
I'm trying to run some code asynchronously within my class (see: https://github.com/duncan3dc/fork-helper). I need to call a series of methods that will modify the values of my properties. I can't seem to do so. I'm trying to use the last example of the call() method on this page: https://duncan3dc.github.io/fork-helper/usage/getting-started/
...ANSWER
Answered 2019-Dec-19 at 11:24The linked library seems to be internally using pcntl_fork
which performs a true fork of the running PHP process. The library mentions "threading" but this is not correct. Forking is a pretty low level operating system concept whereas a process creates a copy of its memory space and instructions in a new process. That new process becomes a child process of the forking process.
This means that everything, like included code and instantiated objects are copied and therefore a child process cannot directly modify the objects of the parent process. The only ways a child process can communicate with the parent is shared memory. In addition the parent can "wait" for the child process to terminate (failing to do this may result in zombie child processes). The linked library does not seem to implement true shared memory but (if you must) you could probably use the PHP shared memory library.
This however is impractical for simple tasks like the one you're sharing. In your case you need to use a true threading library like e.g. pthreads
. Threads, unlike processes, are part of the parent process and share the same memory and data structures and have a significantly lower overhead when context switching.
Note: All the above concepts are pretty low level ones so maybe PHP is not the best choice of language to implement these.
QUESTION
Hi trying to find a way how to run PHP object method in parallel.
Have looked through few solutions on multi-threading with PHP however can't seem to find a way to run object methods in parallel, can someone explain what am i doing wrong and suggest a fix on any of the solutions or alternative example with Country class where get_data method would be running in multiple parallel processes?
- pcntl_fork() - Forking with PHP
- Pthreads - PHP extension
- misterion/ko-process - composer package
- duncan3dc/fork-helper - composer package
- illuminate/queue - composer package
Testing pcntl_fork()
...ANSWER
Answered 2018-Nov-09 at 22:22I can't help with pthreads, ko-process, fork-helper, or queue (I simply don't have experience using them), but this is one method to get your code working with pcntl_fork
and using sockets to pass messages between child and parent process:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install fork-helper
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page