Solved

Logging PHP output

Posted on 2003-11-18
5
462 Views
Last Modified: 2008-03-06
Is there any way to make PHP (or Apache) log the output of a PHP script for debug purposes?

I've tried using SCRIPTLOG in Apache, and can't get it to work using the PHP apache module, so wonder if there's any way of doing it in PHP (or if someone knows how to do it in Apache using the PHP module)

Paul
0
Comment
Question by:pscsuk
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
ThG earned 500 total points
ID: 9770497
The fastest way to do this is using Output Control functions:
http://it.php.net/manual/en/ref.outcontrol.php

basically do something like this:
ob_start();

//do your stuff

and before the end:
$buf = ob_get_contents();
//save $buf in a file, like fopen("myoutput.log", "w");

then you either call ob_flush(); to send the buffer to the browser, or let the script end and it will do it automatically.
0
 
LVL 11

Expert Comment

by:shmert
ID: 9772575
Do you want to log ALL output from a script?  Or just the errors?

If you want all output, go with ThG.  If you want selective logging, you could implement a custom logMessage($message) function that writes to a file.

If you're interested in logging errors, php.ini has settings for directing all error output to a log file.
0
 
LVL 5

Author Comment

by:pscsuk
ID: 9777212
It was all output.

(basically the web browser is doing some bizarre things, like not showing new data even though the PHP script has been called, and another web browser calling the same script works OK - so we want to see what the web browser is getting (we can't use 'Show page source' in the browser, because it's not updating for some reason)

Thanks

Paul
0
 
LVL 14

Expert Comment

by:ThG
ID: 9778120
You may also find this useful:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0

Good luck.
0
 
LVL 5

Author Comment

by:pscsuk
ID: 9779502
It wasn't caching...

Actually, since posting we seem to have fixed the problem, but I don't know how.

Our web server was calling PHP using CGI. I changed this to use the Apache php module, and it all seems to work fine now..

The logs were showing the script returning about 7k to the 'problem' browser, but about 42k to the 'working' browser. That's why I wanted to see what the difference was...

Thanks anyway :-)

Paul
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 …

932 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

16 Experts available now in Live!

Get 1:1 Help Now