简体   繁体   English

Apache / PHP内部服务器错误(500),可能与内存问题有关

[英]Apache/PHP Internal Server Error (500) with possibility related to memory issue

I just moved to a new shared webhosting (PHP 7.0), moved all my files and data from the old one, and then I have this problem on my new server : 我只是移到一个新的共享虚拟主机(PHP 7.0),从旧的文件和数据中移走了所有文件和数据,然后在新服务器上遇到了这个问题:

I have several PHP pages (eg. mypage1.php), which after being loaded in client webbrowser, will load another my PHP pages (via XHR/XMLHttpRequest, eg. mypage2.php, mypage3.php, ..., mypage7.php) to get some data (lets say JSON). 我有几个PHP页面(例如mypage1.php),在加载到客户端Web浏览器中后,将再次加载另一个我的PHP页面(通过XHR / XMLHttpRequest,例如mypage2.php,mypage3.php,...,mypage7.php) )以获取一些数据(比如说JSON)。

When I tried to access mypage1.php in my webbrowser, it gives correct response, but when the browser tried to load mypage2.php, mypage3.php, ..., mypage7.php , it returns "internal server error 500" (server error log: Mon Jul 03 01:50:07.747401 2017] [:error] [pid 612239:tid 139731694188288] (12)Cannot allocate memory: [client xxxx:x] couldn't create child process: /usr/sbin/suphp for /xxx ...). 当我尝试访问Web浏览器中的mypage1.php时,它给出了正确的响应,但是当浏览器尝试加载mypage2.php,mypage3.php,...,mypage7.php时,它返回“内部服务器错误500”(服务器错误日志:2017年7月3日星期一01:50:07.747401] [:错误] [pid 612239:tid 139731694188288](12)无法分配内存:[客户端xxxx:x]无法创建子进程:/ usr / sbin / suphp / xxx ...)。 The error 500 only occurs on some pages (eg. mypage3.php and mypage6.php) 错误500仅在某些页面上发生(例如,mypage3.php和mypage6.php)

On the first place, I thought it just some PHP 'memory_limit' issue, so I tried to solve it by re-configuring (increase from 128M) the memory_limit up to 160M then 192M, but it still failed. 首先,我认为这只是一些PHP'memory_limit'问题,因此我尝试通过将memory_limit重新配置(从128M增加)到160M然后是192M来解决此问题,但是仍然失败。 Then I tried to find out how much my PHP script consume (or allocate) memory, by using memory_get_peak_usage(true) which returns 4,194,304 (it is the max value acquired from mypage2.php - mypage7.php). 然后,我尝试使用memory_get_peak_usage(true)返回4194304(这是从mypage2.php-mypage7.php获取的最大值)来找出我的PHP脚本消耗(或分配)了多少内存。 Doing some test again, the error seems to happen randomly (sometimes all of the pages loaded successfully, and sometimes 1 or 2 or 3 pages failed with the same error message). 再次进行测试,该错误似乎是随机发生的(有时所有页面均成功加载,有时1或2或3个页面因相同的错误消息而失败)。

Which lead me to think, the possibility of Apache's keep-alive configuration, so I checked it, it is active with timeout=5 and max=100, so I think its okay.. but still, I tried to set the HTTP header 'Connection: close' which still did not give me any solution. 这让我想到了Apache保持活动配置的可能性,因此我对其进行了检查,它在timeout = 5和max = 100时处于活动状态,所以我认为还可以。但是,我仍然尝试设置HTTP标头'连接:关闭”,但这仍然没有给我任何解决方案。

Then, I tried to create this simple script, and upload this 'mypage1.php' script : 然后,我尝试创建此简单脚本,并上传以下“ mypage1.php”脚本:

<?php
$param1 = isset($_GET['param1'])? $_GET['param1'] : '';

if($param1==='')
echo('<html><head>
<script type="text/javascript" src="mypage1.php?param1=aaa" ></script>
<script type="text/javascript" src="mypage1.php?param1=bbb" ></script>
<script type="text/javascript" src="mypage1.php?param1=ccc" ></script>
<script type="text/javascript" src="mypage1.php?param1=ddd" ></script>
<script type="text/javascript" src="mypage1.php?param1=eee" ></script>
<script type="text/javascript" src="mypage1.php?param1=fff" ></script>
<script type="text/javascript" src="mypage1.php?param1=ggg" ></script>
</head><body>');
else echo('/* javascript */');
?>

and this amaze me, even this simple script give me the same error 500 (... (12)Cannot allocate memory: ...) This time I meet the dead-end. 令我惊讶的是,即使这个简单的脚本也给了我同样的错误500(...(12)无法分配内存:...)这次我遇到了死胡同。 I dont think it related with the PHP memory issue (or, do you think so?). 我不认为这与PHP内存问题有关(或者,您认为吗?)。 Please give me some feedback, ideas or any story based on your experience, what may cause this problem (or how to solve it). 请根据您的经验给我一些反馈,想法或任何故事,可能导致此问题的原因(或解决方法)。

edit: the error 500 only occurs on some request (eg. mypage1.php?param1=ccc, mypage1.php?param1=fff) 编辑:错误500仅在某些请求下才会发生(例如,mypage1.php?param1 = ccc,mypage1.php?param1 = fff)

Thank you 谢谢

Okay, so I see that you want to secure some javascripts, right? 好的,我知道您想保护一些JavaScript,对不对? It's very bad idea to do validate like this, cause imported (returned by the param) script can be too big to read by the browser and by the server too. 进行这样的验证是一个非常糟糕的主意,因为导入的脚本(由参数返回)可能太大,无法被浏览器和服务器读取。

It can throw HTTP 500, cause server cannot parse that kind of big response. 它会抛出HTTP 500,导致服务器无法解析这种大响应。

The best solution for this is create simple switch inside mypage1 which directly points (and includes) requested javascript file :) 最好的解决方案是在mypage1内创建一个简单的开关,该开关直接指向(并包括)请求的javascript文件:)

Additionaly You can create 1 more php file (simple router for the javascripts) and inside this file you can check that param - after this you can include specified JS or just return JS file name to include it by the main php file :) 另外,您可以再创建1个php文件(用于javascript的简单路由器),并且可以在该文件内检查参数-在此之后,您可以包含指定的JS或只返回JS文件名以将其包含在主php文件中:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM