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 Quote Link to comment 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. Quote Link to comment 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!!! Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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! Quote Link to comment 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? & Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 24, 2007 Share Posted September 24, 2007 frames = evil Quote Link to comment Share on other sites More sharing options...
Damn Posted September 25, 2007 Author Share Posted September 25, 2007 frames = evil Other suggestions? Quote Link to comment 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.. 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.