0

I wrote a page (cron.php) that uses the imap library to connect to a mailbox, parse messages, and store them in a database, then echos the results in json. I have a few dozen mailboxes that I need to run this same process for, and so I put together a page (mailboxes.php) that lists all these accounts, each with a button that when clicked, essentially hits cron.php via AJAX and parses the json response to update the page when the process is completed.

I've noticed however that if I click each of these boxes, they return as if running serially, not in parallel. Is there a configuration option someplace that might explain this?

ehed
  • 804
  • 1
  • 8
  • 18
  • 1
    You're using parallel programming via ajax. That's wrong. http://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser http://www.openajax.org/runtime/wiki/The_Two_HTTP_Connection_Limit_Issue. You can only reliably hope to run 2 ajax requests at any time because of browser limitations. – Mike B Jan 03 '13 at 18:38
  • Thank you. This does also seem to be part of the problem. When I close the sessions they come back more quickly, but also seem to come in pairs. Would this connection limit still be an issue if I invoked the php file via command line (e.g. `php cron.php`)? – ehed Jan 04 '13 at 02:46
  • 1
    Nope, you can start as many processes via command line as you'd like. – Mike B Jan 04 '13 at 02:47

2 Answers2

2

Yeah you need to use session_write_close() on the cron.php file. session_write_close

Pitchinnate
  • 7,517
  • 1
  • 20
  • 37
2

Are you using sessions? Every time you run session_start for given session, it is being locked, until the script finishes, or the session is being 'detached'.

nothrow
  • 15,882
  • 9
  • 57
  • 104