Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I'm having a problem with using 1

Status
Not open for further replies.

roycrom

Programmer
Joined
Aug 2, 2002
Messages
184
Location
GB
Hi, I'm having a problem with using pg_trace. I have the following in a php file:

--------------- start code ----------------------------
<?php
include(&quot;config.inc&quot;);
setcookie($cookie_name,&quot;1&quot;); //setcookie so the counter only increments once

header(&quot;Content-type: image/gif&quot;);
readfile(&quot;images/spacer1.gif&quot;);

include(&quot;function.inc&quot;);

$res=$_REQUEST['res'];

if (!$conn) $conn=db_connect($dbase);
$tracefile=&quot;/tmp/tracefile&quot;;
pg_trace($tracefile);



//the category ID is used to define the page
//****************************************************************
if(!$$cookie_name){ //only do this for the first visit

-------------------break--------------------

there is no output to /tmp/tracefile however. There is very little documentation on this function at php.net. Does anybody use this function that could help me get it working.

Thanks.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Inspect the return value of the pg_trace command. It should return TRUE when the trace file is sucessfully opened.
Let's see what it returns.
Code:
if (!pg_trace($tracefile)) echo(&quot;Error opening trace file&quot;);
 
Thanks for your reply DRJ478,

Ok. The tracefile actually appears in tmp. What happens here is that this php is called from the homepage to update a counter in the postgres db everytime you visit. The file is empty however. My understanding is that it should log all communication that happens on the connection between apache and postgres.

Am I correct in thinking this. The counter DOES get updated so its working in that respect.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Just for completeness I'd try to specify all parameters for the function:
Code:
pg_trace($pathname, 'w+' , $resourceID);
I assume that you open the connection before you enable the trace. Keep that link identifier and stick it in the function call.
Also, according to the PHP documentation the writing parameter defaults to 'w' which always truncates the file to ZERO length before writing. 'w+' appends - so be sure to remove it or rotate the tracefile regularly.
Let's try that.
 
sorry DRJ, what do you mean by the resourceID and how do I determine what it is?

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
When you use pg_connect you get a resource ID for that connection:
Code:
#pg_connect() returns a connection resource that is needed by other PostgreSQL functions
$pgLink = pg_connect(&quot;host=localhost port=5432 dbname=mary&quot;);
The resource identifier can be used to target other commands to a specific connection.
 
DRJ, thanks you for your help, I got pg_trace working and it helped me figure out where my problem was coming from.

In the end all I needed to do was vacuum my pg database which I guess is bad housekeeping on my part but I'm pretty new to this game (but learning fast thanks to lots of thinigs going wrong lol).

Thanks again.

(oh, and you helped me solved my problem so heres a star. :) )

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top