Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(12)Cannot allocate memory: couldn't create child process: /opt/suphp/sbin/suphp

Tags:

php

mysql

apache

Background:

I have a custom CMS website that is MYSQL driven. A php script that connects to a db to load content for the webpage.

Each page loaded connects to the db using the same script.

This includes php, js, css files as well

The script connects to the db is as follows:

$my_link=mysql_connect("localhost",$dbusername,$dbpassword);

@mysql_select_db($database) or databaserror();

One of the pages has the following inside

<link href="/administrator/files/master.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/administrator/files/cbdb-btn.css" />
<link rel="stylesheet" type="text/css" href="/administrator/files/BreadCrumb.css"  />
<link rel="stylesheet" type="text/css" href="/administrator/files/prettyPhoto.css"  />
<link rel="stylesheet" type="text/css" href="/administrator/files/tabs.css" />

<script src="/administrator/files/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/administrator/files/context_menu.js"></script>
<script type="text/javascript" src="/administrator/files/jquery.spinner.js"></script>
<script type="text/javascript" src="/administrator/files/jquery.jBreadCrumb.js"></script>
<script type="text/javascript" src="/administrator/files/jquery_upload.js"></script>
<script type="text/javascript" src="/administrator/files/prettyPhoto.js"></script>
<script type="text/javascript" src="/admin/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/admin/ckeditor/adapters/jquery.js"></script>

All files starting with /administrator/files/ including the file with the above information are mysql driven.

The above file has an establish mysql db

$my_link=mysql_connect("localhost",$dbusername,$dbpassword);

then as it loads the style sheet

<link href="/administrator/files/master.css" rel="stylesheet" type="text/css" />

it connect to the db again using

$my_link=mysql_connect("localhost",$dbusername,$dbpassword);

and it repeats for all .css and .js files.

It doesn't happen on every page refresh however I get an error message 1 in 5 page loads

(12)Cannot allocate memory: couldn't create child process: /opt/suphp/sbin/suphp

Am I connecting to MySQL incorrectly?

If i do not include mysql driven style sheets or js files there are no problems, OR if i load the style sheet pages on their own, there are no problems.

Memory is set to 500mb,

When mysql driven pages are loaded individually the memory stays close to 0mb when more then 1 mysql driven page is loaded, the memory is spiked up to the maximum

Let me know if you require more information.

Thank you

like image 400
user1006368 Avatar asked Nov 05 '22 12:11

user1006368


1 Answers

As i have already told in the comment that you are tying to connect mysql database for each and every query as this may slow down the server uses more memory so connect mysql db once and send as many queries you need or you can try increasing memory limit using the code below

ini_set('memory_limit','200M');

The 20M represents that its 20 Megabytes. Insert the above code in your php script where you want ...

like image 158
Varun Sridharan Avatar answered Nov 09 '22 02:11

Varun Sridharan