Solved

apache crashes with this script

Posted on 2003-11-03
17
411 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:ronn1212
17 Comments
 
LVL 40

Expert Comment

by:RQuadling
ID: 9670152
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.
0
 

Author Comment

by:ronn1212
ID: 9670452
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!!!
0
 

Author Comment

by:ronn1212
ID: 9670595
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?
0
 
LVL 8

Expert Comment

by:inq123
ID: 9672621
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!
0
 
LVL 1

Expert Comment

by:helloAmerica
ID: 9674568
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
0
 

Author Comment

by:ronn1212
ID: 9677402
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
0
 
LVL 8

Expert Comment

by:inq123
ID: 9677879
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.
0
 

Author Comment

by:ronn1212
ID: 9678364
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....
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

by:inq123
ID: 9679499
never used phpdev423 myself, so I can't say.  Maybe somebody else knows?
0
 

Author Comment

by:ronn1212
ID: 9679718
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....
0
 
LVL 8

Expert Comment

by:inq123
ID: 9679744
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.
0
 

Author Comment

by:ronn1212
ID: 9680052
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?
0
 
LVL 8

Expert Comment

by:inq123
ID: 9680489
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, ...
0
 

Author Comment

by:ronn1212
ID: 9686984
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....
0
 
LVL 8

Accepted Solution

by:
inq123 earned 285 total points
ID: 9687192
it's almost for sure me, isn't it?:-)  But you might have been right about the unstable combination.  Did you find documenation of this?
0
 

Author Comment

by:ronn1212
ID: 9693020
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...

0
 
LVL 8

Expert Comment

by:inq123
ID: 9693709
Thanks for your points too!  I just wish I could've been or would be of more help.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now