简体   繁体   中英

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 :

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).

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 ...). The error 500 only occurs on some pages (eg. mypage3.php and 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. 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). 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).

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.

Then, I tried to create this simple script, and upload this 'mypage1.php' script :

<?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. I dont think it related with the PHP memory issue (or, do you think so?). 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)

Thank you

Okay, so I see that you want to secure some javascripts, right? 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.

The best solution for this is create simple switch inside mypage1 which directly points (and includes) requested javascript file :)

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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