Jump to content

How to call multiple functions concurrently


Damn

Recommended Posts

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 :)

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.

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?

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!

 

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?

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.