Solved

Logging PHP output

Posted on 2003-11-18
5
470 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete image(s) associated with record(s) 16 46
Change Wording in Wordpress Plugin 4 40
Conditional Array Element 7 28
Where does this error come from? 8 30
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

751 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