Link to home
Start Free TrialLog in
Avatar of ronn1212
ronn1212

asked on

apache crashes with this script

hello all,
This one is stumping me for quite sometime and who ever will help me solve this will get another 200 points i have with a different user along with 1000 thanks.

I have a big script that it's puprose is to scan a directory and process files and subdirs within this directory.
The processing includes storing in mysql db as well.
I'm using php 4.3.3 with apache 1.3.28 on win2k which I've installed seperatly and manualy. The files i'm processing can vary to be in xml or html format.
Whenever i process the html files apache crashes and gives this error:

"apache.exe has generated some errors and will be closed by windows.
you may need to restart this program. a log file is being created."

I can't see nothing in the apache error log file.
If i take this function out it never ever crashes!

this thing is getting even more strange: it is not crashing all of the times and when it does it is completly random (as i can process many html files in a single run of this script). but always in this script and in the specific html processing function.
it is important to mention that I have a test system which I've installed the php triad package with php 4.06 and apache 1.3.14 on winNT and ther it never ever crashes!!
Another starnge thing is: if i take the sql queries that store the data from the html file to mysql it won't crash as well.

here is the function and it's related function as well:
////////////////////////////////////////////////////////////////////////
function storePatch($patchNo)
{
  //this function will store only a new patch in patches table
  $sql="SELECT id FROM patches WHERE patchId='$patchNo'";
  $result=mysql_query($sql)or die('Query failed: ' . mysql_error());
  if((mysql_num_rows($result) == 0))
     mysql_query("INSERT INTO patches (patchId) VALUES('$patchNo')") or die('Query failed: ' . mysql_error());
  mysql_free_result($result);       
}
////////////////////////////////////////////////////////////////////////
function savePatchData($hpath,$isserver,$site,$audit,$mdate)
{
  /*this function get a path to an html data file. process patch data*/
  $fileAndServer=getFileAndServerLbl($hPath);
  if(!$isServer)
       $server=$fileAndServer["server"]; //file andAndServer gets the server name out of file name
  else
       $server=$isServer;       
   //$filename=$fileAndServer["file"];
 $table=$site."t";
 $saved=false;
 $fileArr=file($hpath);
 $filename=basename($hpath);
 $pattern = '/^([A-Za-z]{2}\-{1}\d{2})/';
 $newArr = array();
 /*get rid of blank lines in file ( all whitespaces lines)*/
  foreach ($fileArr as $line)
  {
   $line=strip_tags($line);
   if(preg_match("/\S/", $line))
    {
        $line=trim($line);
          array_push($newArr, $line);
    }
  }
  /*get rid of html tags*/
  $allArr=explode('|&|',strip_tags(implode('|&|',$newArr)));
  $patchLocN =getPatchLoc($allArr);//will hold position of patches info start
  $patchLocO =getPatchLoc($allArr,1);//will hold position of patches info start
  //handle new patche 4*
  if(!empty($patchLocN))
  {
     for($getNpatch=$patchLocN+1; preg_match("/^\d/",$allArr[$getNpatch]); $getNpatch++)
     {
           $tempPatchArr=explode(' ',$allArr[$getNpatch]);
         $patchNo=trim($tempPatchArr[0]);
         $patchDate=$tempPatchArr[1];
         for($j=3;$j<count($tempPatchArr);$j++)
           $patchDesc.=' '. $tempPatchArr[$j];
         // enter data to database
         $sqlNpatch="INSERT INTO $table (auditId,mdate,server,patchId,patchDate,patchDesc) VALUES ('$audit','$mdate','$server','$patchNo','$patchDate','$patchDesc')";
           mysql_query($sqlNpatch)or die('Query failed fgfd: ' . mysql_error());
         $saved=true;
         unset($patchDesc);
         //no check if patchNo exists on patches table. if no - store it in patches table
         storePatch($patchNo);
     }
  }//if       
  //handle old patche B*
  if(!empty($patchLocO))
  {
     for($getOpatch=$patchLocO+1;preg_match("/^B/",$allArr[$getOpatch]); $getOpatch++)
       {
         $tempPatchArr=explode(',',$allArr[$getOpatch]);
        //enter data to database here
         for($i=0;$i<count($tempPatchArr);$i++)
         {
            if(!empty($tempPatchArr[$i]))
              {
                 $patchNo=trim($tempPatchArr[$i]);
                   $sqlOpatch="INSERT INTO $table (auditId,mdate,server,patchId) VALUES ('$audit','$mdate','$server','$patchNo')";
                     mysql_query($sqlOpatch)or die('Query failed: ' . mysql_error());
                 $saved=true;
                     storePatch($patchNo);
                   
                  }//if       
         }//for  
       }//for
  }//if       
  if($saved)
    return "u";
  else
    return false;      
               
 }
////////////////////////////////////////////////////////////////////////
As I said if i take the queries away it won't crash.
I think it has something to do with the html format...
I have tried everything I could but with no help.
I tried renaming the files and add them a *.txt extension but with no luck.
I'm sure you experienced people wil have some ideas for me because I'm really stumped!!!

Thank you all

Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Instead of executing the queries, can you show the actual query being sent with the values?

e.g.

instead of ...

 $result=mysql_query($sql)or die('Query failed: ' . mysql_error());
  if((mysql_num_rows($result) == 0))
     mysql_query("INSERT INTO patches (patchId) VALUES('$patchNo')") or die('Query failed: ' . mysql_error());
  mysql_free_result($result);      

replace this with ...

 echo "Sending : __$sql__";

The reason for this is that you may have something EXTREMELY wrong with a parameter being sent.

Do this for all the mysql_query() statements.

It does make the script sort of useless and if one query is based on the results of another, you are not going to get anywhere, but hopefully this will give you a starting point.

Regards,

Richard Quadling.
Avatar of ronn1212
ronn1212

ASKER

I just can't understand this thing.
it crashes so randomly.
1 out of three and somtimes it crashes 3 in a row and even one time it didn't crash for 6 staright runs!!! I'm sooo lost on this one.
here are the sql queries (there are a lot because i process a lot of file but i brought one of each kind)

INSERT INTO be1t (auditId,mdate,server,patchId,patchDate,patchDesc) VALUES ('1','2003-06-09','','410143-01','[Apr/29/03]',' R2 MMSOE corrections (component core)')

INSERT INTO patches (patchId) VALUES('410143-01')

INSERT INTO be1t (auditId,mdate,server,patchId) VALUES ('3','2003-07-30','','BB0066-03')

INSERT INTO patches (patchId) VALUES('BB0066-03')

I just can't seem o find anything wrong with it!!!
My guess it's a configuration issue.
Otherwise it wouldn't have worked on my test system with the exact same input, and another clue is that it's unstable (sometimes crashes and sometimet don't) and if it was a script problem it had to be stable on way or another.

anyone has and more ideas for me?
Hi ronn1212,

One thing that should help you is that you shouldn't be looking into Apache's server log file for the error message.  From your description, the error log was generated by WinNT shutting apache down, and the log could be found on your NT computer at START MENU->SETTINGS->CONTROL PANEL->ADMINISTRATIVE TOOLS->EVENT VIEWER->SYSTEM LOG (sometimes application log has some useful info too).  That should give you some idea about where the problem is.

BTW, if it's truly random, then the same html file that's causing trouble at one time might go through in another run, is that the case or not?  If that's the case your best bet is the error log I just mentioned.

PS, I noticed in your code for function savePatchData, the input parameter is $isserver, but in the else statement you used $isServer.  Anything there?

I didn't see any apache or php version specific functions there (not in the two versions you used), so again, check the error log, and check the functions that you called in the code above but didn't show us.

Cheers!
could you please write a statement-by-statement logfile (textfile, fopen('','a') etc so that you may isolate the culprit statement ?

don't forget to flush explicitly after each write

regards
Well, I've looke in win2k system log (START MENU->SETTINGS->CONTROL PANEL->ADMINISTRATIVE TOOLS->EVENT VIEWER->SYSTEM LOG ) and the application log but there nothing added to this logs after apache crashes.
I can't see why is it so unstable.
As for the functions I didn't show - they are really small and simple and the error was there long before I even used them.
I tried to install on my test system another self installing package calles phpdev423. well, it didn't crash but the same script that was expelled in 3 minutes top on both system is expelled with phpdev in 35 minutes!!! can't see why is that either....
something very strange is going on there and I won't rest until I'll solve it as it got PERSONAL :-)

I'd appriciate any further help...
thanks
It's very weird that your system said a log is being generated and you can't find a log in system log and app log.  First of all, sometimes you have to check carefully, 'cause there're so many logs there it's easy to overlook a log that's important to you.  I suggest you do it again because there's no way WinNT does not leave a log there if it says it would.  If you still can't find one, then your winnt has something wrong.

Your problem, with its randomness, sounds very much like a bug that's not worth the effort trying to pin it down.  Instead, reinstalling softwares would probably fix the issue as it might be due to incorrectly installed softwares or software conflicts.  But I wonder you might need to reinstall everything.
Yes you are probabley right...
I've rechecked and there are no logs created (according to date sorting of the logs)
btw, do u have any idea why the same script with the same input runs so slowley on phpdev423 package? where as in the php triad package and the problematic package(which i've installed seperatley and manualy) it's rather fast.
I'm talking big difference.  36 minutes on phpdev as it 170 seconds on the 2 other systems....
never used phpdev423 myself, so I can't say.  Maybe somebody else knows?
basiclly it installs php 4.2.3 with apache 1.3.27 and does all the manual configuration itself...
At least i know it's not my script because both phpdev423 and phptriad self installing packages didn't crash apache....
hmm, can't help you there then.  The only way to check it out is to install these packages myself, but it's scary given its random failures. :-)

I agree with you it's probably not your script, if it's not crashing consistently in one script or with one certain html file.
Can u think of a reason why a script that ran for 2-2.5 minutes with one packahe now runs for 35-40 minutes?
It must been doing a lot of things it shouldn't .. but what?
without looking at the two packages it's hard to say.  It's hard to imagine what could lead to such a huge difference, things that do lead to difference would be: mod_php vs. php cgi, php.ini settings, php version, apache version, ...
Got it!!!
in the last fe days i've tried almost every single combination of php + apache + mysql versions and even tried some self installing packages.
My conclusion is that php 4.3.* in unstable with apache 1.3.*
In most cases it won't crash and you wouldn't notice it but if u had a large complicated script that opens a lot of deirectories and read and store lot's of files it will crash!!
all my problems were solved when i installes php 4.2.3 with apache 1.3.27
of course i had to rewrite some php 4.3.* built in functions but it's a small price to pay for stability.

The first one who'll add another comment will get the points.
(hope its u inq123)
Thanks a lot....
ASKER CERTIFIED SOLUTION
Avatar of inq123
inq123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It might be a good idea to look for a documenation for that but I havn't looked for it yet.
Though I can write my own after installing almost every combination possible
:-)

Anyway the points are yours with many thanks...

Thanks for your points too!  I just wish I could've been or would be of more help.