Solved

Logging PHP output

Posted on 2003-11-18
5
458 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
put constant from select to insert into field  Posgresql 2 39
windows 10 bash shell 4 32
Button Click 11 23
sql sentence 2 10
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 …

772 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

12 Experts available now in Live!

Get 1:1 Help Now