XK8ER
asked on
error with allowed memory
hello there,
how can I prevent an error with allowed size memory..
I have a forum that im checking for valid urls from a mysql query for todays posts..
with this function a url is requested and based on the answer I mark it as good or bad url.
>>Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 25054974 bytes) in script.php on line 23
it usually happens when a link it a video with big size or an exe file or something..
how can I prevent an error with allowed size memory..
I have a forum that im checking for valid urls from a mysql query for todays posts..
with this function a url is requested and based on the answer I mark it as good or bad url.
>>Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 25054974 bytes) in script.php on line 23
it usually happens when a link it a video with big size or an exe file or something..
<?php
function curl($link)
{
global $page;
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 (.NET CLR 3.5.30729)");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
if(eregi("mysite2\.com" , $link)) {
$strCookie = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . "/cookies.txt";
curl_setopt($ch, CURLOPT_COOKIE, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $strCookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $strCookie);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page=curl_exec($ch);
return($page);
curl_close($ch);
unset($link);
unset($ch);
}
?>
sorry, should have clarified. That drupal doc mentions 16Mb.
However your memory is capped at 64Mb at the moment. You could try putting it up to 128Mb for this particular script. Just substitute 128Mb for 16Mb in the drupal docs!
However your memory is capped at 64Mb at the moment. You could try putting it up to 128Mb for this particular script. Just substitute 128Mb for 16Mb in the drupal docs!
ASKER
im trying to fix the issue not increase the memory!
Hi,
The error:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 25054974 bytes) in script.php on line 23
means that you have given 64mb memmory limit in php.ini file. But you have to allocate 25054974 bytes for this purpose. But actually that amount of memmory not allowed in this time. So please increase the memmory_limit variable in the php.ini file to 128mb as well.
Hope this will help you.
Regards
The error:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 25054974 bytes) in script.php on line 23
means that you have given 64mb memmory limit in php.ini file. But you have to allocate 25054974 bytes for this purpose. But actually that amount of memmory not allowed in this time. So please increase the memmory_limit variable in the php.ini file to 128mb as well.
Hope this will help you.
Regards
ASKER
once again.. im here because Im looking for a way to fix this issue not increase the php memory!
ok - what if you change
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
otherwise, the following function from the comments on the PHP CURL manual page is probably going to be of interest to you... you're looking for ($status['http_code'] == 200) to tell you that the link is OK:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
otherwise, the following function from the comments on the PHP CURL manual page is probably going to be of interest to you... you're looking for ($status['http_code'] == 200) to tell you that the link is OK:
function getHttpResponseCode($url)
{
$ch = @curl_init($url);
@curl_setopt($ch, CURLOPT_HEADER, TRUE);
@curl_setopt($ch, CURLOPT_NOBODY, TRUE);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$status = array();
$status = @curl_getinfo($ch);
return $status['http_code'];
}
ASKER
it wont work because im looking for a specific data in the html.. but if its an mp3 or avi file then there is the issue!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://drupal.org/node/207036