Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to rotate php error logs

Posted on 2007-03-23
9
2,784 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

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.

Question has a verified solution.

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

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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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