Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Logging PHP output

Posted on 2003-11-18
5
Medium Priority
?
490 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses

876 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