Reputation: 741
I was trying to setup a multi-threaded socket application, but whenever I ran it I got an error because pcntl_fork()
was disabled by default. Is this because it is dangerous or unstable? Should I look for some other way to multithread, or is it just disabled because it is not often used?
Upvotes: 2
Views: 2261
Reputation: 318488
It simply is a function that should not be used in the average shared-hosting apache environment. Forking there would possibly clone a rather big process and besides that the function can be abused to bring down a poorly configured server (fork bomb).
Using it e.g. in a commandline based PHP script is perfectly fine.
Upvotes: 1
Reputation: 6453
pcntl_fork()
is not for multithreading, it only... well, forks the current proccess. Be sure to check the documentation for more information on the function.
The best reason I can think of it's disable by default, it's because PHP was never meant for parallel computing, it's merely a scripting language (a very powerful one at that). As Martin suggestted on his answer in a similar question, you're better off running a CRON or another program.
Upvotes: 3