Multi-Threading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Multi-Threading

Post 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!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Pcntl is only available when using CLI SAPI
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Ah, So with pcntl_fork, would I create 10 instances and inside each one call the functions i want?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

that's right
Post Reply