lostnucleus Posted February 17, 2009 Share Posted February 17, 2009 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 ......... Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 17, 2009 Share Posted February 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted February 17, 2009 Share Posted February 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
trq Posted February 17, 2009 Share Posted February 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Look into PCNTL functions. Quote Link to comment Share on other sites More sharing options...
trq Posted February 17, 2009 Share Posted February 17, 2009 Look into PCNTL functions. The pcntl functions should not be used within a webserver environment. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 OP never said he was working in such an environment But yeah, good point. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted February 17, 2009 Share Posted February 17, 2009 So what does start_processing() do that takes so long. Surely it's better to optimise that Quote Link to comment Share on other sites More sharing options...
lostnucleus Posted February 17, 2009 Author Share Posted February 17, 2009 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 ?? Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 17, 2009 Share Posted February 17, 2009 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" ); Quote Link to comment Share on other sites More sharing options...
lostnucleus Posted February 17, 2009 Author Share Posted February 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted February 17, 2009 Share Posted February 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted February 17, 2009 Share Posted February 17, 2009 I think the best solution is to use threads and run a user process for each methods you want. What about this link: http://www.alternateinterior.com/2007/05/communicating-with-threads-in-php.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.