Asked by duncanb7
at 2024-05-12 11:15:06
Point:500 Replies:4 POST_ID:828503USER_ID:11059
Topic:
Hypertext Markup Language (HTML);Linux;PHP Scripting Language
I am using curl in php to grab one remote webpage site that is more than 36Meg byte
And I get the fatal error message which is "Out of memory(allocated 3407872( tried to
allocate 3147593 byte) in .../data/include/curl.php on line42" line42 is my $htm=curl_exec($url);
I have checked my php system 's max memory limit is 128M byte by php's phpinfo(). Why I will have such error ?
I go to google it about this at http://drupal.org/node/29268
and I changed my .htaccess file with php_value memory_limit 120M, I talked to my hosting domain support, they just replied it is right there is memory limit=128M byte.
So anyone have suggestion to solve the fatal error issue ?
I also use this in php at the top , ini_set("memory_limit", "120M");, but it still fail
I also use phpinfo() and host support confirm it is 128Meg in my php system.
Any variable use related to curl_exec() is just 2 so it should be less than 120Meg usage in my php ($htm, $file_url)
And attached my .htaccess file and my php sytem configuration.
Is it one variable such as $file_url can not store more than 32Meg byte ?
Please advise & Thanks
Duncan
my php script
=====================
<?php
$file_url=my_curl("wwww.example.com","" , 3000, TRUE);
function my_curl
( $url
, $get_array=array()
, $timeout=3
, $error_report=TRUE
)
{
// PREPARE THE ARGUMENT STRING IF NEEDED
// $get_string = '';
// foreach ($get_array as $key => $val)
// {
// $get_string
// = $get_string
// . urlencode($key)
// . '='
// . urlencode($val)
// . '&';
// }
// $get_string = rtrim($get_string, '&');
if (!empty($get_string)) $url .= '?' . $get_string;
$curl = curl_init();
// HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
$header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK
// SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6' );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $header );
curl_setopt( $curl, CURLOPT_REFERER, 'http://www.google.com' );
curl_setopt( $curl, CURLOPT_ENCODING, 'gzip,deflate' );
curl_setopt( $curl, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
// curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt( $curl, CURLOPT_TIMEOUT, $timeout );
// RUN THE CURL REQUEST AND GET THE RESULTS
$htm = curl_exec($curl);
// ON FAILURE HANDLE ERROR MESSAGE
//global $track; // declaring global variable
if ($htm === FALSE)
{
if ($error_report)
{
$err = curl_errno($curl);
$inf = curl_getinfo($curl);
// echo "FAILC: $url TIMEOUT=$timeout, CURL_ERRNOC=$err";
var_dump($inf);
}
curl_close($curl);
return FALSE;
}
// ON SUCCESS RETURN XML / HTML STRING
curl_close($curl);
return $htm;
}
?>
And I get the fatal error message which is "Out of memory(allocated 3407872( tried to
allocate 3147593 byte) in .../data/include/curl.php on line42" line42 is my $htm=curl_exec($url);
I have checked my php system 's max memory limit is 128M byte by php's phpinfo(). Why I will have such error ?
I go to google it about this at http://drupal.org/node/29268
and I changed my .htaccess file with php_value memory_limit 120M, I talked to my hosting domain support, they just replied it is right there is memory limit=128M byte.
So anyone have suggestion to solve the fatal error issue ?
I also use this in php at the top , ini_set("memory_limit", "120M");, but it still fail
I also use phpinfo() and host support confirm it is 128Meg in my php system.
Any variable use related to curl_exec() is just 2 so it should be less than 120Meg usage in my php ($htm, $file_url)
And attached my .htaccess file and my php sytem configuration.
Is it one variable such as $file_url can not store more than 32Meg byte ?
Please advise & Thanks
Duncan
my php script
=====================
<?php
$file_url=my_curl("wwww.example.com","" , 3000, TRUE);
function my_curl
( $url
, $get_array=array()
, $timeout=3
, $error_report=TRUE
)
{
// PREPARE THE ARGUMENT STRING IF NEEDED
// $get_string = '';
// foreach ($get_array as $key => $val)
// {
// $get_string
// = $get_string
// . urlencode($key)
// . '='
// . urlencode($val)
// . '&';
// }
// $get_string = rtrim($get_string, '&');
if (!empty($get_string)) $url .= '?' . $get_string;
$curl = curl_init();
// HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
$header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK
// SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6' );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $header );
curl_setopt( $curl, CURLOPT_REFERER, 'http://www.google.com' );
curl_setopt( $curl, CURLOPT_ENCODING, 'gzip,deflate' );
curl_setopt( $curl, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
// curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt( $curl, CURLOPT_TIMEOUT, $timeout );
// RUN THE CURL REQUEST AND GET THE RESULTS
$htm = curl_exec($curl);
// ON FAILURE HANDLE ERROR MESSAGE
//global $track; // declaring global variable
if ($htm === FALSE)
{
if ($error_report)
{
$err = curl_errno($curl);
$inf = curl_getinfo($curl);
// echo "FAILC: $url TIMEOUT=$timeout, CURL_ERRNOC=$err";
var_dump($inf);
}
curl_close($curl);
return FALSE;
}
// ON SUCCESS RETURN XML / HTML STRING
curl_close($curl);
return $htm;
}
?>