Re: Does PHP block requests?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ford, Mike wrote:
>> -----Original Message-----
>> From: Peter Ford [mailto:pete@xxxxxxxxxxxxx]
>> Sent: 20 November 2009 15:18
>> To: php-general@xxxxxxxxxxxxx
>> Subject:  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'=>$linesProcessedSoFar);
> 
> 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:

<?php
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 "<p>Done</p>";
?>

and the code for the progress backend is like this:
<?php
$code = 'foo'
if (isset($_SESSION[$code]['count']) && isset($_SESSION[$code]['total']))
{
 header("Content-type: text/xml");
    echo
"{id:'$code',count:'{$_SESSION[$code]['count']}',total:'{$_SESSION[$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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux