GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php server gurus (https://gfy.com/showthread.php?t=956028)

Brujah 02-27-2010 09:13 PM

php server gurus
 
I want this to output '.' as it goes, but some output buffering is taking place and it waits to finish the whole thing before there's any output.

Server runs Apache 2.2.9, no gzip or deflate
php 5.2.6
in php.ini;
output_buffering = Off
implicit_flush = On

Code:

<?php

ob_implicit_flush(true);
ob_end_flush();

$i = 0;
while($i++ < 100)
{
        echo '.';
        usleep(25000);
        if ($i%10==0) echo "\n<br />";
}


borked 02-28-2010 01:17 AM

Code:

<?php

ob_implicit_flush(true);
ob_end_flush();

flush();

$i = 0;
while($i++ < 100)
{
        echo '.';
        sleep(10);
        flush();
        if ($i%10==0) echo "\n<br />";
}

?>

I put the sleep to 10 secs cos I wasn't waiting 40+ mins to see any output ;)

if your server doesn't do the same, compare the headers of:
http://borkedcoder.com/flush.php

with your server. Mine are:
Date: Sun, 28 Feb 2010 08:09:51 GMT
Server: Apache
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

200 OK

Brujah 02-28-2010 01:31 AM

Thanks for the response.
I loaded your page, I'm still waiting for it to output anything.

The usleep(25000) is only 0.025 seconds vs sleep(10) which is 10 seconds.

My headers:
HTTP/1.1 200 OK
Date: Sun, 28 Feb 2010 08:26:04 GMT
Server: Apache
Content-Type: text/html

Brujah 02-28-2010 01:34 AM

Ah! I just tried it in Firefox and it works there, so it must be a Mac Safari and Mac Chrome difference and not server or code related.

borked 02-28-2010 01:59 AM

That's interesting - I didn't know the browsers handled output differently. Indeed Safari is waiting for everything before outputting.
And yup, I changed usleep to sleep cos I though the time was too quick for a browser to capture each flush separately, but then was waiting forever, so consider that remark as me talking to myself ;)

So, looks like nothing you can do there if it's the browser handling that's the problem.

HomerSimpson 02-28-2010 02:22 AM

try adding this line

set_time_limit(0);

calmlikeabomb 02-28-2010 07:08 AM

http://www.ape-project.org/ - check that out.

Naechy 02-28-2010 07:45 AM

answer him

Brujah 02-28-2010 12:51 PM

I thought about using AJAX, but just wondered why the php solution wasn't working. There's nothing wrong with the code, it's just the browser differences.

If you pad about 1,000 space characters with some new lines or other characters first, it starts to flush the output for the other browsers.

No need for extra flush() or ob_flush(), and set_time_limit isn't necessary.


All times are GMT -7. The time now is 03:42 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123