Solved

Logging PHP output

Posted on 2003-11-18
5
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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