Jump to content
MakeWebGames

PHP Memory Limit


hobbes

Recommended Posts

Looks like I've finally hit my allowed limit on my server.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes)

If I remove a pre-existing php script on my server, will this allow room for other php scripts to be used or is it all cached? Other words, what are my options other than switching to a semi/dedicated server.

Link to comment
Share on other sites

Re: PHP Memory Limit

It sounds like the script that encountered that error needs a little optimization.

As far as I know, that sort of error is encountered when one script exceeds the memory limit, not when all users accessing a php script combined exceed it. ;)

The cause of the error is most likely a for loop, while loop, or some other sort of loop that has run amuck.

Link to comment
Share on other sites

Re: PHP Memory Limit

Aah, ok, that makes more sense. And yes, there is a foreach loop. I'm not quite sure if your familiar with mc's car mod script, but it only affects the tune.php script. I would post the foreach loop for evaluation, but am not sure what the rules are when posting parts of a paid modification?

Link to comment
Share on other sites

Re: PHP Memory Limit

Very true Floydian, and I would really love to. The only thing is, Dabomstew hasn't been online here for over a year. :wink:

I also wanted to correct a mistype in my previous post, its with carmadd.php and not through a for loop, it's a SQL query that is giving me that error. That being said, I have no problems in sharig this quote from the script with the rest of you.

 

$q=mysql_query("SELECT iv.*,i.* FROM cars_playercars iv LEFT JOIN cars_types i ON iv.cpcCAR=i.carID WHERE cpcID={$_GET['ID']} and cpcPLAYER=$userid",$c);

I have also tried

 

$q=mysql_query("SELECT `cpcID` FROM `cars_playercars` WHERE `cpcID` = {$_GET['ID']} and `cpcPLAYER` = $userid",$c);

and the exact same message. The SQL tables are generic just like any other and I don't understand how I am getting this Fatal Error.

Link to comment
Share on other sites

Re: PHP Memory Limit

Try taking the query, and running it manually (i.e., php myadmin, mysql command line, or some other mysql application).

This is your query string. You just need to fill in the variables. If you don't know the values, echo this string:

"SELECT iv.*,i.* FROM cars_playercars iv LEFT JOIN cars_types i ON iv.cpcCAR=i.carID WHERE cpcID={$_GET['ID']} and cpcPLAYER=$userid"

 

or echo it:

echo "SELECT iv.*,i.* FROM cars_playercars iv LEFT JOIN cars_types i ON iv.cpcCAR=i.carID WHERE cpcID={$_GET['ID']} and cpcPLAYER=$userid"

 

See what that does when you run it manually.

Link to comment
Share on other sites

Re: PHP Memory Limit

No issues there. I changed the cpcID and cpcPlayer value to one in the database and received a normal query result.

 

cpcID cpcPLAYER cpcCAR cpcACCLV cpcHANLV cpcSPDLV cpcSHDLV carID carNAME carDESC carCOST carACC carHAN carSPD carSHD carBUYABLE

1 166 1 1 1 1 1 1 Mini Roxi The Mini Roxi is a very compact car. It is not des... 3000 2 2 2 2 1

Link to comment
Share on other sites

Re: PHP Memory Limit

normally you can create a php.ini file and put it your web root and it should use your settings compared to the webhosts standard settings.

possible ways

create a php.ini and ad following line adjust 12M if needed to higher

memory_limit = 12M

or through htaccess add

php_value memory_limit 12M

again adjust/increase memory value as needed

if these don't work contact your webhost as proposed by floydian

Link to comment
Share on other sites

Re: PHP Memory Limit

Thanks for your responses. I have tried changing the memory_limit higher among other things. Only the server admin can change it and they told me that it's restricted to 32mb and that the only option i have is to switch hosts. A real shame as this is the only script that has given me this headache.

Link to comment
Share on other sites

Re: PHP Memory Limit

I still think it has something to do with a loop. I don't know how long that script is, but I've got scripts that span 3 to 5 thousand lines of code, and crons that can take more than 30 seconds to execute. But it's only when I get a loop that has run amuck that I get a memory error like that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...