I have a simple PHP script running as a cron job, it's purpose is to check the headers of a webpage and report if various items have changed.
I have used various versions of this script in the past and it has always worked fine, but now I'm using it on a server that sends out warnings by email when scripts are using more than 100Mb of memory (apart from whitelisted scripts of course), and surprisingly my header-checking script is occasionally reporting large amounts of memory usage at least a few times a day.
The script is running every 5 minutes, and the memory problem is happening 5 or 6 times a day - it does seem to resolve itself, but I would like to stop it from using this large amount of memory occasionally for such a simple job.
The warning emails are reporting usage of around 290Mb for this simple script :
<?php
$message = "";
function array_find ($needle, $haystack, $search_keys = false) {
if (!is_array($haystack)) return false;
foreach ($haystack as $key => $value) {
$what = ($search_keys) ? $key : $value;
if (strpos($what, $needle) !== false) return $key;
}
return false;
}
$url = 'http://www.EXAMPLE.com/';
$haystack = get_headers($url);
$needle = "PHPSESSID";
if (!((array_find($needle, $haystack)) != '')) {
$message .= "No PHPSESSID in headers";
}
if (!(strpos($haystack[0], '200'))) {
$message .= "No 200 OK";
}
if ($message != '') {
mail("example@example.com", "Headers Changed", $message, "From: Example <example@example.com>");
}
exit;
?>
The server is a VPS running CENTOS 5.8, Apache 2.2.16, PHP 5.3.3
Thanks for any assistance.