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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。