Current location: Hot Scripts Forums » Programming Languages » PHP » MultiThreading in PHP on Unix


MultiThreading in PHP on Unix

Reply
  #1 (permalink)  
Old 08-03-03, 03:34 PM
Damien Damien is offline
New Member
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
MultiThreading in PHP on Unix

Hi Readers,

Heres what i'm trying to achieve:

A script, that uses multiple fsockopen()'s and simltaniously get feedback from each socket from fget()s. Now, since using a single fget() needs to be in a loop then it's not possible to have more than one loop going at the same time.

I was thinking of using a break command, then getting feedback from the other loops, and breaking each of them inside a encapsulating loop - however, this is VERY ineffective.

What I thought about doing was just using the same script launched multiple times, so it has diffrent proccesses running and therefore would be able to complete the task of having multiple loops running at the same time on the same system.

The problem I've found out is that on Unix (the desired OS breed), PHP can't be forked - so using a start.php script to execute multiple system() calls wouldn't work becuase PHP waits till the system() function has finished before carrying on with the rest of start.php.

i.e. The following won't work:

PHP Code:



for ($i 0$i 5$i++) {
  
system ("/path/to/php /path/to/script.php &");

Basically, i'm asking if anyone has a work around, or alternativley a answer to my problem?

I'd much appritiate it, or any help you can contribute.

Thanks in advance, or for atleast reading to this point

-Damien
Reply With Quote
  #2 (permalink)  
Old 08-03-03, 07:00 PM
jv2222 jv2222 is offline
The Freshmaker
 
Join Date: Jun 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
On all UNIX systems PHP can be forked.. if it is run from the command line and.. if it was compiled with --enable-pcntl.

See process controll functions in the manual.

Another option that you may wish to explore is register_tick_function ( string func [, mixed arg])

register_tick_function registers the function named by func to be executed when a tick is called.

A tick is an event that occurs for every N low-level statements executed by the parser within the declare block. The value for N is specified using ticks=N within the declare blocks's directive section.

The event(s) that occurs on each tick is specified using the register_tick_function().

Ticks are well suited for debugging, implementing simple multitasking, backgrounded I/O and many other tasks.

Cheers,
Justin
__________________
Author of <a href=http://www.hotscripts.com/Detailed/18290.html target=_blank>ezSQL</a> (makes life soooo easy when working with databases)
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP Dudes - Hi All stuart New Members & Introductions 4 05-03-04 01:22 PM
Custom PHP Scripts BdSBB Job Offers & Assistance 3 12-07-03 09:49 AM
PHP Triad/Upload form eddyvlad PHP 6 10-06-03 11:17 PM
managing linux users from php asinclair PHP 0 09-22-03 06:08 AM


All times are GMT -5. The time now is 04:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.