Page 1 of 1

Multi-Threading

Posted: Mon Apr 09, 2007 8:46 am
by GeXus
I understand that PHP does not support multi-threading. However, this is what I would like to do and maybe there is a solution.

I currently have a script that calls a function I wrote 10 times with different criteria. As it stands, it goes down the line.. finishing one, going to the next, etc. Is there anyway I can have it call the 10 functions concurrently... without having to execute 10 different files.

Thanks!

Posted: Mon Apr 09, 2007 8:53 am
by Chris Corbyn
Not in complete syncronisation like threading no. You can fork new processes with pcntl_fork(), or you can use fsockopen() to spawn new processes over HTTP. PHP isn't the right language for anything that needs syncronized events.

Posted: Mon Apr 09, 2007 9:07 am
by Weirdan
Pcntl is only available when using CLI SAPI

Posted: Mon Apr 09, 2007 9:07 am
by GeXus
Ah, So with pcntl_fork, would I create 10 instances and inside each one call the functions i want?

Posted: Mon Apr 09, 2007 9:17 am
by Weirdan
that's right