0

I have a PHP script which opens a socket connection(using fsockopen) and takes about 15secs to complete/return the result to the browser. Mean while, if the browser sends a second request it is serialized. This is giving a bad user experience because if the user clicks 3 times, then the third request which gets sent after 30sec is the one that gets the response -- the first 2 requests from browser prespective are getting lost.

I do not have any session in my script, but tried putting session_write_close() at the beginning of my script which didnt help.

Also session.auto_start in the php.ini = 0.

Any ideas as to how to make the client requests from the same browser parallel??

Thanks Gary

Gary
  • 3
  • 1
  • This is about how you initiate the connections from the client, not what's on your server. It's a JavaScript/websockets question, not PHP. – Dan Grossman Dec 14 '10 at 05:25
  • Did you use stream_context_create(). Edit your question and add some code part to get more idea about the issue. – Manu Dec 14 '10 at 05:43

2 Answers2

1

1) Download and install Firefox

2) Download and install Firebug

3) Add a sleep(10) to your PHP script so that it pauses for a few seconds before returning its response

4) Open up your webpage, and watch the outbound connections with Firebug. You should see several that are open and do not yet have a response. They should all return at about the same time, when each one finishes the 10 second delay.

If you do not see multiple connections open at the same time, and return at approximately the same time, then you need to look at your front end code. AJAX requests are asynchronous and can run in parallel. If you are seeing them run serially instead, then it means you need to fix your JavaScript code, not anything on the server.

Parallel asynchronous Ajax requests using jQuery

Community
  • 1
  • 1
Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
  • I analyzed the wireshark packets and see that the next request goes off from the browser only after it gets a response from the previous request. So, this seems like a client issue. Thank you all for the responses. I will keep you posted on my findings. – Gary Dec 14 '10 at 15:04
0

You should if at all possible install(*nix) redis.

To install just do simple

make

With lpush/brpop you can handle this stuff asynchronously and keep order intact. If you spawn couple of worker threads you could even handle multiple requests simultaneous. the predis client library is pretty solid

Alfred
  • 60,935
  • 33
  • 147
  • 186