How to rotate php error logs


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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

php uses webserver logging facilities, so rotatelogs is to be used
srini_kandimallaAuthor Commented:
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.

Not sure what you mean by 5M
This value should be expressed in seconds.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

srini_kandimallaAuthor Commented:
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?

rotatelogs parameter #2 is syntactically wrong. It will not work.
You will not find documentation to back your missassumptions.
srini_kandimallaAuthor Commented:
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# pwd
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"


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.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srini_kandimallaAuthor Commented:
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 ??



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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.