Re: calling a function multiple times
| From: | (Aaron Bishell) | Date: | Wed, 19 Mar 2003 19:26:52 +0000 |
| Subject: | Re: calling a function multiple times | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-3111@lists.php.net to get a copy of this message | ||
It sounds like you need threads or forking? If your running *nix you could
use pcntl_fork: http://www.php.net/manual/en/function.pcntl-fork.php.
Unfortunately nothing exists for W32 that allows two different processes
to be executed simultainiously. Threads development is underway here:
http://chora.php.net/cvs.php/pear/PECL/threads
but seems to have stagnated.
Jared D. Hurn wrote:
> Hello,
> This might not make sense, so I'll try to explain it as best as
> possible. I am writing an application that acts kind of like a task
> scheduler. The scheduling component of this application gets a list of
> the jobs it needs to do every hour and then calls a function which is
> in charge of handling all the jobs. Some of these jobs take a long
> time to do, and I am worried about not having enough time in an hour
> to process each job consecutively. So what I would like to do is
> process multiple jobs at once, but I can't seem to figure out how to
> do this. PHP-GTK waits till each job is finished before it moves on to
> the next job, which is what I expected it to do since that's the way
> function calling works. I'd use something like mikehup if I could get
> it to work on my win2k system. I tried using gtk::timeout_add to call
> the function so as not to pause the calling function, but it still
> wants to wait until doAgentJob is finished. I hope I have giving an
> understandable description of my problem, sorry if it doesn't make
> sense.
> Also, I can not use cron or any other similar task scheduling program,
> I must stick to the scheduling capabilities of my application.
> Any help would be greatly appreciated!
> Here is the segment of code in question:
> function doAgentJob($jobID)
> {
> $jobj = &new jobObject();
> $jobj->doJob($jobID);
> }
> function schedulerAgent()
> {
> // MySQL Login
> include_once('mysql-login.inc');
> $glade_app = &$GLOBALS['glade_app'];
> $font = &$GLOBALS['font'];
> $schedulerState = &$GLOBALS['schedulerState'];
> if($schedulerState)
> {
> // Updates Window
> $entry = "Agent Proccess Done @ " . date('Y-m-d H:i:s', time()) .
chr(10);
> $widget = $glade_app->get_widget('txtMain');
> $widget->insert($font, null, null, $entry);
> $widget->set_word_wrap(FALSE);
> $widget->set_line_wrap(FALSE);
> // Creates the job handling object
> $jobj = &new jobObject();
> // Returns an array of ids
> $jobIDs = $jobj->getJobs();
> // Goes through and processes all the job ids returned
> for($i = 0; $i < count($jobIDs); $i++)
> {
> // Checks to see how many jobs are currently being processed
> $query = "select * from job_list where jobStatus='1'";
> $result = mysql_query($query);
> // I want to limit the number of jobs that can be processed
> // at the same time
> if(mysql_num_rows($result) < 3)
> {
> // If there are less than 3 jobs being processed do another
> // one
> $jobID = $jobIDs[$i];
> // I would like for the script to keep going, but it waits
> // here until the function is done doing its thing
> doAgentJob($jobID);
> }
> else
> {
> // If there are 3 jobs running, wait till one of them is done
> // to do another one
> $i--;
> // Wait 30 seconds before trying to add a job
> sleep(30);
> }
> }
> return(TRUE);
> }
> else
> return(FALSE);
> }
> /*---
> Best regards,
> Jared D. Hurn (jdhurn@ubermancer.com)
> Lead Developer
> http://www.uberMancer.com:8080
> ---*/