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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.