Jump to content

How to excecute multiple functions at a same time ??


lostnucleus

Recommended Posts

I have a start_processing("set 1") function which takes 6 hrs to complete set1 ,

I want to process set 2, set 3 .... how can i process all of them in same time ?? since when i put

 

<?php

start_processing("set1");

start_processing("set2");

start_processing("set3");

?>

 

It takes 18 hrs .........

You could only reduce it down so much, and that would require a CPU with multiple cores.. if you have a single core CPU there's nothing you can do to reduce the time other than resort to faster C modules or improving your algorithms (why 6 hours?). As far as multi-threading in PHP? I have no idea how you can do that, I've never needed to look into it.

dunno that you can multi-thread in php, since it is essentially a procedural language, even a call to an object or an included function resolves itself completely in the line of the file that called it, then php moves on to the next line

 

my suggestion would be 3 diff browser windows, each working on 3 diff pages with one function each... but then the server might take a crap

dunno that you can multi-thread in php, since it is essentially a procedural language

 

So is C, yet you can impliment threads in that.

 

my suggestion would be 3 diff browser windows, each working on 3 diff pages with one function each

 

My suggestion would be (if this script really takes 6 hours to execute) not execute it via your server at all. Execute it in the background from the command line.

my program uses command line (not webroser)

start_processing() is an function which consist an while loop which again consist sleep(20) , it download files , since you can just download nonstop hence it has to wait 20 sec for that .

 

I dont know abt PCNTL Functions much so i am currently reading that page..........

Is the below thing possible

 

variable_array[] = new yo_class($set1);

variable_array[] = new yo_class($set2);

variable_array[] = new yo_class($set3);

 

i.e multiple objects has been created with a array variable ??

You can break up your code into 3 PHP files. And try to use the "system" function that will run these programs independently...

 

system( "file1.php" );

 

system( "file2.php" );

 

system( "file3.php" );

Your idea was good but the number of sets (no of files) is not fixed (could be 3 or more ),hence its not gona work.

dunno that you can multi-thread in php, since it is essentially a procedural language

 

So is C, yet you can impliment threads in that.

 

so thorpe... can you in php?

 

my suggestion would be 3 diff browser windows, each working on 3 diff pages with one function each

 

My suggestion would be (if this script really takes 6 hours to execute) not execute it via your server at all. Execute it in the background from the command line.

 

heh... that makes more sense

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.