A
A
aptik2014-07-31 14:59:29
PHP
aptik, 2014-07-31 14:59:29

With multiple simultaneous calls to the script, some queries return an empty page. What's wrong?

There is a PHP script:

/*
...
достаем нужный путь к файлу из базы по информации с реквеста
$name = 'етот путь';
...
*/

$fp = fopen($name, 'rb');
header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header("Content-Type: image");
header("Content-Length: " . filesize($name));
fpassthru($fp);
exit;

My .htaccess file redirects all requests like image/c0b7fbb39f425760b61eab96f53fee5a_53d7b7b513a9d.png to this script, which in turn fetches the desired path by hash and returns the contents of the image file.
Everything works as intended. But in a situation where there are many such images on one page, some of them are not shown. Instead of getting a picture, I get this response with an empty body:
Remote Address:x.x.x.x:80
Request URL:http://...image/c0b7fbb39f425760b61eab96f53fee5a_53d7b7b513a9d.png
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ru,en-US;q=0.8,en;q=0.6,uk;q=0.4
Connection:keep-alive
Cookie:PHPSESSID=7o1ouvllm0smad14s952dh5fq1; yii-debug-toolbar=hide; _ga=GA1.2.281170268.1406016085
Host:host.com
Referer:http://.../images
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

The problem is clearly not in the files themselves, because after loading such a page, pictures that were not shown may appear completely normal, and, in turn, pictures with which there were no problems may not appear.
Ubuntu 14.04.1 LTS
Apache/
2.4.7 PHP 5.5.9-1ubuntu4.3 (apache module)

UPD :
Moved the question to /tmp as the problem was elsewhere. YiiDebugToolbar made its way into the pictures. I had to disable it dynamically for this controller.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Zheltyakov, 2014-07-31
@VitaZheltyakov

By chance, there is no link to the session in the php script?

I
Igor, 2014-07-31
@merryjane

Show the output of the command:
apachectl -M

A
Alexander Kubintsev, 2014-07-31
@akubintsev

You can see the apache access + error logs.
I also thought about the lack of workers in apache, but it seems like the 200th status code ...

A
Alexey Pavlov, 2014-07-31
@lexxpavlov

The erroneous response does not contain your headers, which are set by the script. Maybe something causes an error, content is being served, and the headers are no longer being sent.
I understand that there is another code before the specified code?
Is this a plain php script, outside of yii?
How many files are in your images folder?
Write the first line of the script (if there is no such line already):
And tell if your headers will start appearing in the browser in these erroneous downloads.
Add more before fpassthru
ob_end_clean();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question