Re: fail on preg_match_all

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just a follow-up on this, the problem was 'Fatal error: Allowed memory size of 8388608 bytes exhausted'

After some nice help, I found that this is actually a common problem with intense regexes in php. Quick fix is using ini_set() to increase your memory_limit to something massive, like '400M'. This gives your script access to that much memory for its life-time. If you have this problem, then you probably also have to do this

set_time_limit(0);  //remove any max execution time

Hamilton


PS - for anyone confused, here was the script . . . i didnt think it was that confusing, sorry guys!

function parse_access($file_name)
{
   // read file data into variable
   $fh = fopen($file_name, 'r') or die("cant open file for reading");
   $theData = fread($fh, filesize($file_name));
   fclose($fh);

   // perform regex
$regex = '!(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}) - - \[(\d{2})/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Aug|Oct|Nov|Dec)/(\d{4}):(\d{2}):(\d{2}):(\d{2}) -\d+] {1,4}"GET ([._0-9\-%a-zA-Z/,?=]+) ([.0-9a-zA-Z%/\-,_?]+)" (\d{3}) (\d+) \[(.+?)] \[(.+?)] \[(.+?)] (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)!';
   //echo $regex . '<br><br><hr><br>';
   $num = preg_match_all($regex, $theData, $match, PREG_SET_ORDER);
   //echo "after regex - we are still alive!";

//go on to do some boring stuff, like write this to an array, perform stuff, graph stuff, blah blah
}




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux