Solved

How to rotate php error logs

Posted on 2007-03-23
9
2,755 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Htaccess - if subdomain "dev." 2 77
apache and php 3 109
apache vhosts on mac not being recognized 5 81
setup wamp server for first time 2 67
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

14 Experts available now in Live!

Get 1:1 Help Now