double0201 2017-06-26 11:39
浏览 70
已采纳

无法分配内存,无法创建子进程:我是否需要对PHP映像请求进行排队?

Update 3aug 2017:

I've tried out a simple test. I made a PHP-file with the following content:

<?php
echo "<img src='http://www.hependos.fi/testgetimage.php?file=2016-11-02_1478082625_zKW3xUPF.jpg'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<br><br>";
echo "<img src='http://www.hependos.fi/Ikonit/test/2016-11-    02_1478082625_zKW3xUPF.jpg'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
echo "<img src='SIMILARLINKWITHANOTHERFILENAME'>";
?>

and the testgetimage.php-file contains the following:

<?php

$KuvaReferenssi = basename(urldecode($_GET["file"]));

$fileDir = "Ikonit/test/";

$file = $fileDir . $KuvaReferenssi;
$type = 'image/jpeg';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($file));
readfile($file);

?>

The images with a fixed source display correctly each time, but with the php-file-as-source files once again do not show up correctly, on average 2/5 images appear correctly.

The images are the smallest I could find on my server with a single file has a size of 4.4kb.

PHP error says:


Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 2312704 bytes) in /home/hependos/public_html/testgetimage.php on line 57

Cpanel's error log states the same as mentioned below.

What am I doing wrong here?

Thanks in advance!


Original post

I'm having trouble displaying my images on my web-pages. The images are being fetched by a php-script.

The images on the pages have the source of a .php-file which fetches an image based on a filereference. website.c om/getImage.php?file=filename

And then the part of the php-file that actually sends the image to the browser has the content of:

if (file_exists($fileDir . $file)){
$contents = file_get_contents($fileDir . $file);
echo $contents;}

Of course the filename and directory is fetched from a database and used as the variable $file there.

The actual problem is that the servers Virtual memory is capped really easily (fetching 6 images, each sized around 200kb), resulting in HTTP500.

Cpanels error log states (for each HTTP500):

[Sun Jun 25 15:31:00.131534 2017] [:error] [pid 398316:tid 140190395291392] (12)Cannot allocate memory: [client 85.76.42.74:50544] couldn't create child process: /usr/sbin/suphp for /home/username/public_html/getImage.php, referer: http://www.website.com/index.php

This is really an issue as some images don't load at all (there is no specific order in which they decide to appear or not to appear).

I've tried to contact my service-provider but they keep saying "Myes, the server's capacity is topped out.".

This can't be the case as there is hardly any traffic other than myself and a few others on my server. And the requests I send are very small (text-based article and then these images).

But the thing is, am I missing something on the image-fetch? Am I supposed to clean-up some variables or free-up memory for use after each fetch?

I don't use any libraries or anything, I've written everything myself.

I'll be happy to reply to any further questions in order to get this thing going, its really frustrating. :(

Edit 28.06 15:06 I replaced the those 3 lines and tried out the readfile()-function like this:

echo readfile($fileDir . $row['KuvaNimi']);

but no difference. Out of 6 images, 5 never show up.

  • 写回答

1条回答 默认 最新

  • dousaoxiancy199896 2017-08-10 13:23
    关注

    After 6 months of reviewing, testing and struggling with my code, it wasn't my code in the first place. My service provider had a deprecated option left on in Linux's LVE-options. They didn't specify too much more, but that was the issue causing all these symptoms here.

    Thanks everyone who sacrified your thoughts to this, its finally up and running as it should be. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP