Damn Posted September 19, 2007 Share Posted September 19, 2007 Howdy all. I have a php function that is passed some parameters, and goes off a fetches some data from a remote source, and returns it. This php function, is being called by a loop, on another php page. The function, always takes approx 2.5 seconds to run. The issue I have is that on a particular page, the function might be called by a loop 4 or even 20 times. Because the loop calls the function, waits for it to complete before it loops around and calls it again, we are only having the function run serially, eg: one at a time. The function is not disk, cpu or network intensive. If many instances of the function were called at once, they would still only take 2.5 seconds to run. So my question is - how can I have this function run concurrently? This might stray away from PHP a bit, the only idea I had was to have the php code output javascript code, which, once the page has been output, calls all the functions at once. Any info anybody can offer will be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/ Share on other sites More sharing options...
trq Posted September 19, 2007 Share Posted September 19, 2007 You can't run functions concurrently within php. Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-350792 Share on other sites More sharing options...
ToonMariner Posted September 19, 2007 Share Posted September 19, 2007 hmmm it sounds like you are doind something inefficiently... can we see some code? 2.5 seconds is like a lightyear on a server!!! Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-350810 Share on other sites More sharing options...
d22552000 Posted September 19, 2007 Share Posted September 19, 2007 he offers a good question though, is there a way to put things to run concurrently... In ASP there is a workaround to make asp run two things at once, but it is weird and doesnt work to well.. PHP, doesnt have such a feature as far as I know. Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-350816 Share on other sites More sharing options...
Damn Posted September 19, 2007 Author Share Posted September 19, 2007 Hello, Thanks for your replies so far. 2.5 seconds is because it must place a call into a remote server, load up the page, scrape the bits we want & return them. Now before you all jump to conclusions (happened on another forum) this isn't spambot code or anything like that, its just that another company we are grabbing info from can't give it to us in any other way (for the moment). So I can't have php do it - could I do it via javascript or ajax? Or am I asking the wrong audience? Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-350838 Share on other sites More sharing options...
ToonMariner Posted September 24, 2007 Share Posted September 24, 2007 is there no way to collate all these parameters and grab ALL the bits in one request? That shoudl be much faster than calling the function over and over again, creating the connection (which is where the time will kill you)? Alternatively some ajax that just grabs the content once it is requested would be an excellent solution - if js is on that is! Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-353966 Share on other sites More sharing options...
rarebit Posted September 24, 2007 Share Posted September 24, 2007 What about using exec() to fire off a script in a new process, results dumped in files in a dir to be harvested later? & Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-353969 Share on other sites More sharing options...
Damn Posted September 24, 2007 Author Share Posted September 24, 2007 Well so far I have had the php echo out a series of IFRAME's - and those call the php function that grabs the data. I don't know if this is the way I should keep it - at least it works & doesn't rely on JS, not sure if IFRAME will be around for ever though? Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-354462 Share on other sites More sharing options...
Dragen Posted September 24, 2007 Share Posted September 24, 2007 frames = evil Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-354471 Share on other sites More sharing options...
Damn Posted September 25, 2007 Author Share Posted September 25, 2007 frames = evil Other suggestions? Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-354481 Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 If we could see some code we may be able to suggest a quicker way of doing it.. Link to comment https://forums.phpfreaks.com/topic/69831-how-to-call-multiple-functions-concurrently/#findComment-354855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.