LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-09-2017, 07:48 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
Apache php script does not work correctly when invoked


Hi group,
I have a php script that will not work correctly unless I use it to create a HTML file. The script reads from the Apache logs and creates a web page.
That does not work right, but if I pipe the script to create a HTML file, the output is correct? The code:
Code:
<?php

#if( !isset($_GET["log"])) $Log = "access.log"; 
#else                      $Log = $_GET["log"] . ".log";
#echo "$Log";

$Sort = fopen( "sort.dat", "w" );

exec( "sudo /bin/cat /var/log/apache2/access.log.1" .
      "/var/log/apache2/access.log" ,
      $output, $rc );

if( $rc != 0 ) {
  echo "RC: $rc\n cat failed\n<br>";
  var_dump( $output );
  exit; }

$Count = count( $output );
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
     <meta content="text/html; charset=ISO-8859-1"
       http-equiv="content-type">
     <title>Apache Access Log</title>
     </head>
   
   <body style="background-color: rgb(204, 204, 204); color: windowtext;"
      alink="#ee0000" link="#0000ee" vlink="#551a8b">
      </body>
  <center> 
  <Table border="5" width="100%" >
     <tbody>
       <tr>
	   <th>Date</th>
	   <th>Request</th>
           <th>Code</th>
           <th>Client</th>
	   <th>Type</th>
           </tr>
<?php

$Line = array();
$Date = array();
$Day  = array();

   foreach($output as $Record) {

      $Line = explode(" ", $Record);

      $Temp = $Line[3];

      $Date = explode( ":", "$Temp" );

      $Time = "$Date[1]" . ":" . "$Date[2]" . ":" . "$Date[3]";

      $Temp = $Line[5];

      $Request = substr( $Temp, 1 );

      $Day     = explode( "/", "$Line[3]" );

      $Day[0]  = substr( $Day[0], 1 );

      echo "       <tr>\n"
	  ."         <td>" . "$Day[0]  " . "$Time" . "</td>\n"
	  ."         <td>" . "$Request" . "</td>\n"
	  ."         <td>" . "$Line[8]" . "</td>\n"
	  ."         <td>" . "$Line[0]" . "</td>\n"
	  ."         <td>" . "$Line[6]" . "</td>\n"
	  ."         </tr>\n";

      $NL = $Line[6] . "\n";
      $RC = fputs( $Sort, $NL , strlen( $NL ) );  }

   echo "<tr><td colspan=\"5\"><center>Count: $Count</td></tr>" .
        "</tbody></table>\n";

   echo "<br>List by request\n";

   echo "<Table border=\"10\" width=\"100%\" ><tbody>\n";

   fclose( $Sort );

   exec( "sort sort.dat | uniq -c | sort -n", $Output, $rc );

   foreach( $Output as $Record ) {
 
      $Line = explode( " ", trim( $Record ) );
      echo "<tr><td>"  .
	   "$Line[0]"  .
	   "</td><td>" .
	   "$Line[1]"  .
	   "</td></tr> \n"; }

   echo "</tbody></table>";
	       
?>

</html>
The first part works OK but the second table is not outputed
for the second table if run as a php script by the Apache server. If I use this CLI:
Code:
 php /WebServer/log.php > /WebServer/LOG.html
and create an HTML file, it works right?

Any ideas?

Thanks for your time.
 
Old 03-09-2017, 08:15 PM   #2
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Never mind, for some reason it now works!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Unable to run part of background shell script when invoked by PHP, Please advise. har_85 Programming 8 03-10-2015 05:41 AM
PHP 5 + Apache not configured correctly. Clean3d Linux - Server 1 09-24-2007 11:06 AM
php will NOT work correctly :( arichardson Fedora 8 11-18-2005 07:28 AM
php will NOT work correctly :( arichardson Fedora 3 11-17-2005 03:10 PM
Apache-ssl not correctly parsing php files jme Linux - Software 2 05-03-2005 12:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration