Does PHP block requests?

Does PHP block requests?

am 20.11.2009 16:17:48 von Peter Ford

I have a tricky problem.

I'm trying to make a progress feedback mechanism to keep users informed about a
slowish process on the server end of a web app. The backend is generating a PDF
file from a bunch of data which extends to many pages. I can keep tabs on the
progress of this generation by working out how many lines of data is present,
and how much of it has been processed. I use that information to set a session
variable with a unique name - so for each step I set

$_SESSION['some-unique-name']=>Array('total'=>$totalLines,'c ount'=>$linesProcessedSoFar);

Now on the front end I'm doing an AJAX call to a script that just encodes this
session variable into a JSON string and sends it back.

The problem is that while the PDF is being generated, the AJAX calls to get the
progress data (on a 1-second interval) are being blocked and I don't get why.
The PDF generation is also triggered by an AJAX call to a script which generates
the PDF in a given file location, then returns a URL to retrieve it with.

So it appears that the problem is that I can't have two AJAX calls to different
PHP scripts at the same time? WTF?

Checking the requests with Wireshark confirms the the browser is certainly
sending the progress calls while the original PDF call is waiting, so it's not
the browser side that's the problem: and once the PDF call is finished the
outstanding progress calls are all serviced (returning 100% completion of course
- not much use!) Different browsers (Firefox, IE, Chrome at least) give the same
result.

For reference, the server is Apache 2.2.10 on a SuSE linux 11.1 box using
mod_php5 and mpm_prefork - is that part of the problem, and is there an alternative?
--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Does PHP block requests?

am 20.11.2009 16:32:08 von M.Ford

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBQZXRlciBG
b3JkIFttYWlsdG86cGV0ZUBqdXN0Y3JvZnQuY29tXQ0KPiBTZW50OiAyMCBO
b3ZlbWJlciAyMDA5IDE1OjE4DQo+IFRvOiBwaHAtZ2VuZXJhbEBsaXN0cy5w
aHAubmV0DQo+IFN1YmplY3Q6IFtQSFBdIERvZXMgUEhQIGJsb2NrIHJlcXVl
c3RzPw0KPiANCj4gSSBoYXZlIGEgdHJpY2t5IH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GFuZCBhbGwgdGhlIHBy
b2dyZXNzLWNoZWNraW5nIGNhbGxzIGFyZSBibG9ja2VkIHVudGlsIHRoZSBz
ZXNzaW9uIGF1dG8tY29tbWl0cyBhdCB0aGUgZW5kIG9mIHRoZSBnZW5lcmF0
b3Igc2NyaXB0LiBUbyBjb3VudGVyIHRoaXMsIHlvdSBuZWVkIHRvIG1hbnVh
bGx5IHNlc3Npb25fY29tbWl0KCkgc29tZXdoZXJlIG5lYXIgdGhlIGJlZ2lu
bmluZyBvZiB0aGUgZ2VuZXJhdG9yIHNjcmlwdC4NCg0KQ2hlZXJzIQ0KDQpN
aWtlDQogLS0gDQpNaWtlIEZvcmQsDQpFbGVjdHJvbmljIEluZm9ybWF0aW9u
IERldmVsb3BlciwgTGlicmFyaWVzIGFuZCBMZWFybmluZyBJbm5vdmF0aW9u
LCAgDQpMZWVkcyBNZXRyb3BvbGl0YW4gVW5pdmVyc2l0eSwgQzUwNywgQ2l2
aWMgUXVhcnRlciBDYW1wdXMsIA0KV29vZGhvdXNlIExhbmUsIExFRURTLMKg
IExTMSAzSEUswqAgVW5pdGVkIEtpbmdkb20gDQpFbWFpbDogbS5mb3JkQGxl
ZWRzbWV0LmFjLnVrIA0KVGVsOiArNDQgMTEzIDgxMiA0NzMwDQoNCg0KDQoK
ClRvIHZpZXcgdGhlIHRlcm1zIHVuZGVyIHdoaWNoIHRoaXMgZW1haWwgaXMg
ZGlzdHJpYnV0ZWQsIHBsZWFzZSBnbyB0byBodHRwOi8vZGlzY2xhaW1lci5s
ZWVkc21ldC5hYy51ay9lbWFpbC5odG0K

Re: Does PHP block requests?

am 20.11.2009 17:40:07 von Peter Ford

Ford, Mike wrote:
>> -----Original Message-----
>> From: Peter Ford [mailto:pete@justcroft.com]
>> Sent: 20 November 2009 15:18
>> To: php-general@lists.php.net
>> Subject: [PHP] Does PHP block requests?
>>
>> I have a tricky problem.
>>
>> I'm trying to make a progress feedback mechanism to keep users
>> informed about a
>> slowish process on the server end of a web app. The backend is
>> generating a PDF
>> file from a bunch of data which extends to many pages. I can keep
>> tabs on the
>> progress of this generation by working out how many lines of data is
>> present,
>> and how much of it has been processed. I use that information to set
>> a session
>> variable with a unique name - so for each step I set
>>
>> $_SESSION['some-unique-
>> name']=>Array('total'=>$totalLines,'count'=>$linesProcessedS oFar);
>
> The progress-counter Ajax script uses a session -- but does the PDF generator use the same session? If so, I'm guessing you don't manually close the session at any point and all the progress-checking calls are blocked until the session auto-commits at the end of the generator script. To counter this, you need to manually session_commit() somewhere near the beginning of the generator script.
>
> Cheers!
>
> Mike
> --
>
You're right about trying to use the same session - that was the plan to get the
progress state passed across from one call to the other.
Closing the session on the generator script has the effect of stopping any
further changes to the session variable, so I get the initial value at each
request after that.

I put together a simple "Generator" script to test this:

session_commit();
header("Content-type: text/xml");
$fcode = 'foo';
$_SESSION[$fcode]=Array('total'=>10,'count'=>0);
for ($i=0; $i<10; $i++)
{
sleep(1);
$_SESSION[$fcode]['count']++;
}
echo "

Done

";
?>

and the code for the progress backend is like this:
$code = 'foo'
if (isset($_SESSION[$code]['count']) && isset($_SESSION[$code]['total']))
{
header("Content-type: text/xml");
echo
"{id:'$code',count:'{$_SESSION[$code]['count']}',total:'{$_S ESSION[$code]['total']}'}";
}



What I get now is that the session variable is set to 1 out of 10, but never
changes after that.

Perhaps I can do it with some other message passing mechanism (e.g. a temporary
file) instead of the $_SESSION.
Thanks for you help so far...

Cheers,

Pete

--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Does PHP block requests?

am 20.11.2009 22:57:04 von M.Ford

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBQZXRlciBG
b3JkIFttYWlsdG86cGV0ZUBqdXN0Y3JvZnQuY29tXQ0KPiBTZW50OiAyMCBO
b3ZlbWJlciAyMDA5IDE2OjQwDQoNCg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