Solved

How to rotate php error logs

Posted on 2007-03-23
9
2,821 Views
Last Modified: 2008-03-04
Hi,

I am using Apache & PHP on Solaris.
The question is regarding PHP error logs.

In my php.ini file, the following flags are set as below.

log_error = On
log_errors_max_len = 1024.

If I set as above, am I going to get mutilple php_error.logs each of 1024 size or always I get only one php_error.log of 1024 size.

But for the above setting, my log size is grwoing beyond 1024 also.

My requirement here is that I should have similar functionality of  "rotatelogs" of httpd for php_error.logs.
That is, once php_error log exceeds 1024, the new php_error log should be created and should also have the old php_error.log

Similar functionality of Piped logging using rotatelogs of httpd.

Thanks  
0
Comment
Question by:srini_kandimalla
  • 5
  • 4
9 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 18784544
php uses webserver logging facilities, so rotatelogs is to be used
0
 

Author Comment

by:srini_kandimalla
ID: 18793888
In my php.ini file

I replaced the  error_log = /opt/xxx/zzz/apache/logs/php_error.log

with this below statement for rotating logs purpose, but it did not work.

ErrorLog "|/opt/xxx/zzz/apache/bin/rotatelogs /opt/xxx/zzz/apache/logs/php_error.log 5M"

My assumption is that TransferLog and ErrorLog work only in httpd.conf file, not using php.ini file.
When I revert back the changes, the php_error.logs are created.

Thanks
0
 
LVL 62

Expert Comment

by:gheist
ID: 18795931
Not sure what you mean by 5M
This value should be expressed in seconds.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:srini_kandimalla
ID: 18795989
5M tells the size of log. The ErrorLog and TransferLog macros accepts it instead of seconds. Once log size exceed 5M size it will rotate to new log.
My basic questions here is that whether we can ise TranLog and ErrorLog macros of httpd.conf in php.ini or not?

Thanks
0
 
LVL 62

Expert Comment

by:gheist
ID: 18799266
rotatelogs parameter #2 is syntactically wrong. It will not work.
You will not find documentation to back your missassumptions.
0
 

Author Comment

by:srini_kandimalla
ID: 18801353
You can use both options, such as, Seconds as well as Size ( 5M).
This I am working on Solaris.
If you go to apache bin direcotry and give the rotate logs command, you can see both options.
But this documentation I too could not find on the net, I found it thru the command on Solaris.
It is as below. I tired this command for size and worked for me.

My basic question is that the TransferLog and ErrorLog directives whether they work by using php.ini or not instead of http.conf file. That is the php.ini supports these two commands or not. Answer to this is suffient for me, if it works any syntax changes for php.ini


The below is output of on Solaris

dev-sun-xyz#
dev-sun-xyz# pwd
/opt/xxx/zzz/apache/bin
dev-sun-xyz# ./rotatelogs
Usage: ./rotatelogs [-l] <logfile> <rotation time in seconds> [offset minutes from UTC] or <rotation size in megabytes>

Add this:

TransferLog "|./rotatelogs /some/where 86400"

or

TransferLog "|./rotatelogs /some/where 5M"

to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the
system time at which the log nominally starts (N.B. if using a rotation time,
the time will always be a multiple of the rotation time, so you can synchronize
cron scripts with it). At the end of each rotation time or when the file size
is reached a new log is started.
dev-sun-xyz#

Thanks
0
 
LVL 62

Accepted Solution

by:
gheist earned 500 total points
ID: 18802744
I've got apache 1.3 and assumed its features.

So - is your apache logs rotating?

error_log has multiple values:

    Name of the file where script errors should be logged. The file should be writable by the web server's user. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: syslog(). If this directive is not set, errors are sent to the SAPI error logger. For example, it is an error log in Apache or stderr in CLI.

basically comment out error_log line and read apache error log instead. php does no log rotations.
0
 

Author Comment

by:srini_kandimalla
ID: 18803455
Yes, my apache logs are rotating with Size (5M) option.

If you look at my orginal question at the top, I metnioned that
log_error = On
log_errors_max_len = 1024

what does it mean of "log_errors_max_len = 1024" in while logging PHP errors.
Is it size of error log file or length of error string line length in error file of php ??

Thanks

0
 
LVL 62

Assisted Solution

by:gheist
gheist earned 500 total points
ID: 18813907
http://ee.php.net/manual/en/ini.php
http://ee.php.net/manual/en/ref.errorfunc.php#ini.log-errors-max-len

log_error prevents server from presenting errors in webpages.
_max_len is size of logged error /think of long SQL statement/
error_log is used to avoid default logging to apache error log

I am not english, so please consult reference manual firsthand.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Post form data to PHP then to 3rd party site 19 45
tomcat LDAP authentication issue 3 229
file path 14 72
Recommendations for Web-Based Multi-User File Manager / FTP software? 4 137
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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