I have a XML parser in php which reads an XML file and inserts the contents to database. This does it for a single file. But i have hundreds of files, and hundreds more will be added daily.
- So how should i do multi tasking in php so that i can parallel process more than 1 file.
- How to do it more efficiently the multi tasking
You can use
pcntl_fork(), this is the “classic” UNIXfork()method. Note this only works on UNIX/Linux systems and the the CGI/CLI SAPI.AFAIK there is no
vfork()in PHP, so it’s not very memory efficient.There are no threads in PHP. The lack of proper multi-processing is probably the biggest handicap of the language.
I wrote a little guide on using
pcntl_fork()some time ago, you can use it as a starting point if you wish. There are more out there, use Google.Or, you can just start your script multiple times in the background… Depending on your script, this may be easier …