php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6021 Script is getting killed although it doesn't consume very much memory
Submitted: 2000-08-08 09:26 UTC Modified: 2000-12-07 11:27 UTC
From: juhl at eisenstein dot dk Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (08/08/2000) OS: Slackware Linux 7.0
Private report: No CVE-ID: None
 [2000-08-08 09:26 UTC] juhl at eisenstein dot dk
After upgrading to latest CVS I'm getting errors due to the memory limit that I've not encountered before. 

Even small scripts (that worked perfectly with PHP 4.0.0) are now getting killed when theyt hit my mem-limit of 25MB. 

I think something is leaking memory since I do not get this error for about the first hour after restarting Apache, but after aproximately 1 hour the scripts start to crash with this message:

Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 256 bytes) in Unknown on line 0

Running "top" or "ps" shows no processes using huge amounts of mem, and each httpd process is consuming about 3% of my 128MB RAM each time they run.

Restarting apache makes the problem go away again for about half an hour to an hour.


I'm running Slackware Linux 7.0, Apache 1.3.12, PHP 4.02-dev (php4-200008080345). PHP was configured like this:
./configure  --with-mysql=/usr/local/mysql --with-apxs=/usr/local/apache/bin/apxs --with-config-file-path=/etc/httpd --enable-calendar --enable-trans-sid --enable-versioning --enable-track-vars --with-gd --with-jpeg-dir --with-tiff-dir --with-png-dir --with-ttf --with-zlib-dir --enable-memory-limit=yes --with-openssl --disable-debug


Best regards,
Jesper Juhl

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-08 09:57 UTC] stas@php.net
Please provide reproducing script for this behaviour.
 [2000-08-08 10:28 UTC] juhl@php.net
The following script exhibits the described behaviour (the amount of time until the problem shows itself can vary depending (I guess) on server load).

The function makeStrSafe() is defined in juhlFunctions.php and looks like this:

function makeStrSafe($str) {
	$str = trim($str);
	$str = eregi_replace("[^-a-zA-Z?????? 0-9.,_]", "", $str);
	return $str;
}

The session.php file is rather large, and so is the db.php file that defines the db class (included in session.php), so I'll only post them on request.
The err_return() function currently does nothing, it's just defined like this:

function err_return($a, $b) {
	exit();
}


<?php
$INCLUDE_DIR = "/include/";
require($DOCUMENT_ROOT.$INCLUDE_DIR."juhlFunctions.php");
$username = makeStrSafe($username);
$password = makeStrSafe($password);
require($DOCUMENT_ROOT.$INCLUDE_DIR."session.php");
$k = makeStrSafe($k);
if ($k != $klub) {
	$klub = $k;
}
session_register("klub");

if (empty($klub)) {
	header("Location: http://".$SERVER_NAME."klubVaelger.php");
	exit();
}

$dbase = new db;
if (!$dbase->connect()) {
	err_return($dbase->errno, $dbase->errmsg);
}

$filename = "medlem_forside.php";
if (!($fp = fopen($filename, "r"))) {
	err_return("r", "Kunne ikke &aring;bne filen $filename");
}
if (!($contents = fread($fp, filesize($filename)))) {
	err_return("r", "Kunne ikke l&aelig;se filen $filename");
}
fclose($fp);

$dbase->query = "LOCK TABLES klub READ, person READ";
if (!$dbase->execQuery()) {
	err_return($dbase->errno, $dbase->errmsg);
}

$dbase->query = "SELECT navn FROM klub WHERE post_id='$klub'";
if (!$dbase->execQuery()) {
	err_return($dbase->errno, $dbase->errmsg);
}
if (mysql_num_rows($dbase->result) == 0) {
	echo "Klubben findes ikke<br>";
	exit();
}
$row = mysql_fetch_array($dbase->result);
$contents = eregi_replace("<klubNavn>", "$row[navn]", $contents);

$dbase->query = "SELECT fornavn, efternavn FROM person WHERE post_id='$row[leder_id]'";
if (!$dbase->execQuery()) {
	err_return($dbase->errno, $dbase->errmsg);
}
$row = mysql_fetch_array($dbase->result);
$contents = eregi_replace("<klubLederNavn>", $row[fornavn]." ".$row[efternavn], $contents);

$dbase->query = "UNLOCK TABLES";
if (!$dbase->execQuery()) {
	err_return($dbase->errno, $dbase->errmsg);
}


echo $contents;

?>

 [2000-08-14 03:37 UTC] juhl@php.net
I'm currently using php4-200008130745 and compiled it without memory limit (that is, without the --enable-memory-limit configure parameter), and now everything seems to be working nicely, and I have no problems with scripts or apache processes consuming a lot of memory, but if I enable the memory-limit, then the scripts start dying again... Could there be a bug regarding  --enable-memory-limit?


Regards,
Jesper Juhl
juhl@eisenstein.dk

 [2000-11-01 11:13 UTC] sniper@php.net
Please try a newer snapshot. This might be fixed now.

--Jani
 [2000-12-07 11:27 UTC] sniper@php.net
Reopen, if this still happens when using latest snapshot
from http://snaps.php.net/

--Jani
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 20:00:02 2026 UTC