[UPHPU] logging to a file

Brady Mitchell mydarb at gmail.com
Sat Dec 30 14:42:11 MST 2006


Hey Orson,

It depends on what kind of data you are wanting to keep track of. If you 
want to log errors to a custom location take a look at 
set_error_handler() and trigger_error(). You first use 
set_error_handler() to define a function to handle the errors, then when 
you want to trigger an error in your code, use trigger_error().

Depending on the data being logged and how you plan to use it, it may be 
worthwhile to log to a database instead of a file. If it is errors that 
you need to log, that can be setup using set_error_handler().

In the example code you gave, you would probably want to use flock() to 
prevent multiple writes to the same line in the file.

HTH,

Brady


Orson Jones wrote:
> I was wondering about doing some logging to a file in an application I am building.
> 
> I am wondering if there are hidden problems with doing something like the following. (Particularly with simultaneous attempts.)
> 
> $fp = fopen("data.txt", "a");
> $fputs($fp, $data);
> fclose($fp);
> 
> Are there more reliable ways of doing this, or is it sufficient?
> 
> Orson Jones
> 
> 
> _______________________________________________
> 
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
> 



More information about the UPHPU mailing list