[PHP] fail on preg_match_all

2008-02-20 Thread Hamilton Turner

Does anyone know why a server would simply fail on this line?

$num = preg_match_all($regex, $theData, $match, PREG_SET_ORDER);

if i know the file handle is valid (i grabbed it using 'or die'), and 
the regex is valid


hamy

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] fail on preg_match_all

2008-02-20 Thread Hamilton Turner
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 . '';
   $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

}