S
S
Stanislav2016-09-28 19:53:23
PHP
Stanislav, 2016-09-28 19:53:23

What could be the difference between two servers handling buffer flushes differently in php?

The point is this. There are two servers, here are their versions:

1. PHP 5.4.45 (cli) (built: Jun 17 2016 17:55:12)
2. PHP 5.5.30-1~dotdeb+7.1 (cli) (built: Oct  1 2015 17:38:39)

There is a php code:
header("HTTP/1.1 200 OK");
header("Connection: close");
ob_start();
echo __FILE__."<br>";
$size = ob_get_length();
header("Content-Length: $size");
sleep(2);
ob_end_flush();
flush();
sleep(2);
phpinfo();

which serves simply to test one mechanism of operation. It consists in the fact that you must first send a 200 response to the client calling the processing of this code and close the connection, and then do something else. This is required to work with one of the Internet services, which has a webhook time limit of 5 seconds, otherwise it disconnects due to a timeout and after some time tries to repeat the webhook (request).
.htaccess looks like this:
<IfModule mod_php5.c>
  # disable compressing
  php_flag zlib.output_compression off
  SetEnv no-gzip 1
</IfModule>

<FilesMatch \.php$>
    SetEnv no-gzip 1
</FilesMatch>

<IfModule mod_deflate.c>
  RemoveOutputFilter DEFLATE html txt xml css js php
</IfModule>

Options -Indexes

In general, I took everything I could find on the Internet.
So on server 2, everything happens as it should, judging by the log in the Chrome debugger:
https://yadi.sk/i/r_TWWuUEvrTff
And on the first server, this picture
https://yadi.sk/i/2Xa65xO7vrTeS
then there is no return of content in the middle of the script happens. What could be the problem and where to run, what to disable or enable?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav, 2016-09-29
@lamo4ok

Well, the study of manuals and tests made themselves felt. Here is the code that worked as it should:

header("HTTP/1.1 200 OK");
header("Connection: close");
ob_start();
phpinfo();
$size = ob_get_length();
header("Content-Length: $size");
ob_flush();
sleep(2);
echo __FILE__."<br>";

with this .htaccess:
<FilesMatch \.php$>
    SetEnv no-gzip 1
</FilesMatch>

What was needed?
1. In .htaccess, it was necessary to leave only disabling gzip for php files, it turns out that it was still enabled and this affects the portions of the web server that will give content, despite my code.
2. A difference was found in the server configs, the output_buffering variable on the server that processed the code as expected, this variable has the value of no value (on the "correct" server this value is set to 4096).
Perhaps, in the end, the buffer size is taken from somewhere else, and as a result, the pages on which I tried to display some lonely line first were simply not given out from the buffer for output. Once I increased the size of the page by doing php_info() everything fell into place. The verdict is to either give a larger page (a hack) or change the settings for working with the buffer in such a way that the ob_flush() function is guaranteed to send the contents of the buffer to the client.

O
OnYourLips, 2016-09-28
@OnYourLips

You approached the problem from the wrong side.
When you receive a request from a user, you simply save it to the queue.
And you process such requests as a background process.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question