Pierre Far
Rotating php-fpm.log hourly
June 24, 2009 03:59PM
Hello all

First time here and need some help with the php-fpm.log file. Is there
a way to rotate the log on an hourly basis?

Background: I've been noticing that the the log file grows *very*
quickly. It reaches a file size of 2147483647 (2.0GB according to ls -
lFah) and then it's matter of time before php-fpm crashes. If I mv the
log file to something else and create a new log file, on reboot
everything works fine. If I don't do this manual log rotation, php-fpm
just doesn't start and fails to restart.

So how can I rotate the logs at high frequency?

Thanks,
Pierre
Davy Campano
Re: Rotating php-fpm.log hourly
June 24, 2009 04:36PM
Hi Pierre,
You could do it a couple ways. To rotate the log file, you would just need
to move the current log file and then issue a SIGUSR1 to the php-fpm
process.

i.e.

mv /opt/php/logs/php-fpm.log /opt/php/logs/php-fpm.log.1
kill -SIGUSR1 `cat /opt/php/logs/php-fpm.pid`

Obviously replacing the paths to wherever your pid and log files are :)

Also you could use logrotate but I think this usually runs once per day, not
positive on that. Then logrotate would keep 3 logs and rotate only if size
is over 100MB.

Here is a sample logrotate that you would put into /etc/logrotate.d/php-fpm

/opt/php/logs/php-fpm*log {
size=100M
rotate 3
missingok
notifempty
sharedscripts
postrotate
kill -USR1 `cat /opt/php/logs/nginx.pid`
endscript
}

Hope that helps!

Davy

On Wed, Jun 24, 2009 at 3:59 PM, Pierre Far wrote:

>
> Hello all
>
> First time here and need some help with the php-fpm.log file. Is there
> a way to rotate the log on an hourly basis?
>
> Background: I've been noticing that the the log file grows *very*
> quickly. It reaches a file size of 2147483647 (2.0GB according to ls -
> lFah) and then it's matter of time before php-fpm crashes. If I mv the
> log file to something else and create a new log file, on reboot
> everything works fine. If I don't do this manual log rotation, php-fpm
> just doesn't start and fails to restart.
>
> So how can I rotate the logs at high frequency?
>
> Thanks,
> Pierre
>
Davy Campano
Re: Rotating php-fpm.log hourly
June 24, 2009 04:39PM
Accidentally said nginx.pid instead of php-fpm.pid
/opt/php/logs/php-fpm*log {
size=100M
rotate 3
missingok
notifempty
sharedscripts
postrotate
kill -USR1 `cat /opt/php/logs/*php-fpm.pid*`
endscript
}

On Wed, Jun 24, 2009 at 4:36 PM, Davy Campano wrote:

> Hi Pierre,
> You could do it a couple ways. To rotate the log file, you would just need
> to move the current log file and then issue a SIGUSR1 to the php-fpm
> process.
>
> i.e.
>
> mv /opt/php/logs/php-fpm.log /opt/php/logs/php-fpm.log.1
> kill -SIGUSR1 `cat /opt/php/logs/php-fpm.pid`
>
> Obviously replacing the paths to wherever your pid and log files are :)
>
> Also you could use logrotate but I think this usually runs once per day,
> not positive on that. Then logrotate would keep 3 logs and rotate only if
> size is over 100MB.
>
> Here is a sample logrotate that you would put into /etc/logrotate.d/php-fpm
>
> /opt/php/logs/php-fpm*log {
> size=100M
> rotate 3
> missingok
> notifempty
> sharedscripts
> postrotate
> kill -USR1 `cat /opt/php/logs/nginx.pid`
> endscript
> }
>
> Hope that helps!
>
> Davy
>
> On Wed, Jun 24, 2009 at 3:59 PM, Pierre Far wrote:
>
>>
>> Hello all
>>
>> First time here and need some help with the php-fpm.log file. Is there
>> a way to rotate the log on an hourly basis?
>>
>> Background: I've been noticing that the the log file grows *very*
>> quickly. It reaches a file size of 2147483647 (2.0GB according to ls -
>> lFah) and then it's matter of time before php-fpm crashes. If I mv the
>> log file to something else and create a new log file, on reboot
>> everything works fine. If I don't do this manual log rotation, php-fpm
>> just doesn't start and fails to restart.
>>
>> So how can I rotate the logs at high frequency?
>>
>> Thanks,
>> Pierre
>>
>
>
Pierre Far
Re: Rotating php-fpm.log hourly
June 24, 2009 04:44PM
Thanks, Davy.

> mv /opt/php/logs/php-fpm.log /opt/php/logs/php-fpm.log.1
> kill -SIGUSR1 `cat /opt/php/logs/php-fpm.pid`
Is there a way to rename with a serial number, like a timestamp
instead of just .1?

> Also you could use logrotate but I think this usually runs once per day, not positive on that.  Then logrotate would keep 3 logs and rotate only if size is over 100MB.
>From my research, I think you're right that it's once daily.

Thanks,
Pierre

--
Pierre Far, PhD
pierrefar@gmail.com

Know before your site crashes: http://SocialAlerter.com/
Webmaster and SEO resources: http://ekstreme.com
Blog of Science: http://blogsci.com
Short URLs with analytics: http://cli.gs/
Re: Rotating php-fpm.log hourly
June 24, 2009 09:09PM
Pierre Far Wrote:
-------------------------------------------------------
> Thanks, Davy.
>
> > mv
> /opt/php/logs/php-fpm.log /opt/php/logs/php-fpm.l
> og.1
> > kill -SIGUSR1 `cat /opt/php/logs/php-fpm.pid`
> Is there a way to rename with a serial number,
> like a timestamp
> instead of just .1?
>
A simple shell script like this ought to do it:

[code]
#!/bin/bash
cd /usr/local/logs
stamp="$(date +%s)"
mv php-fpm.log php-fpm.log.$stamp
kill -SIGUSR1 `cat php-fpm.pid`
#gzip or delete or process however you like
gzip php-fpm.log.$stamp
exit
[/code]

Call it "rotate.sh" or whatever you like, make it executable, and run it as a cron every hour or however often you like. Note my path to php-fpm logs and pid is /usr/local/logs/. You need to use whatever your path(s) are. This will stamp the file with unix time so a log file will look like "php-fpm.log.1245891191" or " php-fpm.log.1245891191.gz" if gzipped.

>
> > Also you could use logrotate but I think this
> usually runs once per day, not positive on that.
>  Then logrotate would keep 3 logs and rotate only
> if size is over 100MB.
> >From my research, I think you're right that it's
> once daily.
>
> Thanks,
> Pierre
>
> --
> Pierre Far, PhD
> pierrefar@gmail.com
>
> Know before your site crashes:
> http://SocialAlerter.com/
> Webmaster and SEO resources: http://ekstreme.com
> Blog of Science: http://blogsci.com
> Short URLs with analytics: http://cli.gs/

--
Jim Ohlstein
Re: Rotating php-fpm.log hourly
June 25, 2009 02:41AM
might as well use logrotate though.
copy nginx's almost identical :)

On Wed, Jun 24, 2009 at 6:09 PM, Jim Ohlstein wrote:

>
> Pierre Far Wrote:
> -------------------------------------------------------
> > Thanks, Davy.
> >
> > > mv
> > /opt/php/logs/php-fpm.log /opt/php/logs/php-fpm.l
> > og.1
> > > kill -SIGUSR1 `cat /opt/php/logs/php-fpm.pid`
> > Is there a way to rename with a serial number,
> > like a timestamp
> > instead of just .1?
> >
> A simple shell script like this ought to do it:
>
>
> #!/bin/bash
> cd /usr/local/logs
> stamp="$(date +%s)"
> mv php-fpm.log php-fpm.log.$stamp
> kill -SIGUSR1 `cat php-fpm.pid`
> #gzip or delete or process however you like
> gzip php-fpm.log.$stamp
> exit
>
>
> Call it "rotate.sh" or whatever you like, make it executable, and run it as
> a cron every hour or however often you like. Note my path to php-fpm logs
> and pid is /usr/local/logs/. You need to use whatever your path(s) are. This
> will stamp the file with unix time so a log file will look like
> "php-fpm.log.1245891191" or " php-fpm.log.1245891191.gz" if gzipped.
>
> >
> > > Also you could use logrotate but I think this
> > usually runs once per day, not positive on that.
> > Then logrotate would keep 3 logs and rotate only
> > if size is over 100MB.
> > >From my research, I think you're right that it's
> > once daily.
> >
> > Thanks,
> > Pierre
> >
> > --
> > Pierre Far, PhD
> > pierrefar@gmail.com
> >
> > Know before your site crashes:
> > http://SocialAlerter.com/
> > Webmaster and SEO resources: http://ekstreme.com
> > Blog of Science: http://blogsci.com
> > Short URLs with analytics: http://cli.gs/
>
> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?3,3333,3345#msg-3345
>
>
Re: Rotating php-fpm.log hourly
June 25, 2009 08:27AM
Michael Shadle wrote:
> might as well use logrotate though.
Most systems default to run logrotate once a day. He's looking for an
hourly solution. You can set logrotate to run hourly but that won't take
care of the timestamp in the file name which he wanted (unless there's a
setting for that in logrotate - I don't know, I never looked). Anyway,
it's a simple script. Feel free to use it or not. It took about two
minutes for me to write it.
>
> copy nginx's almost identical :)
>
> On Wed, Jun 24, 2009 at 6:09 PM, Jim Ohlstein <nginx-forum@nginx.us
> <mailto:nginx-forum@nginx.us>> wrote:
>
>
> Pierre Far Wrote:
> -------------------------------------------------------
> > Thanks, Davy.
> >
> > > mv
> > /opt/php/logs/php-fpm.log /opt/php/logs/php-fpm.l
> > og.1
> > > kill -SIGUSR1 `cat /opt/php/logs/php-fpm.pid`
> > Is there a way to rename with a serial number,
> > like a timestamp
> > instead of just .1?
> >
> A simple shell script like this ought to do it:
>
>
> #!/bin/bash
> cd /usr/local/logs
> stamp="$(date +%s)"
> mv php-fpm.log php-fpm.log.$stamp
> kill -SIGUSR1 `cat php-fpm.pid`
> #gzip or delete or process however you like
> gzip php-fpm.log.$stamp
> exit
>
>
> Call it "rotate.sh" or whatever you like, make it executable, and
> run it as a cron every hour or however often you like. Note my
> path to php-fpm logs and pid is /usr/local/logs/. You need to use
> whatever your path(s) are. This will stamp the file with unix time
> so a log file will look like "php-fpm.log.1245891191" or "
> php-fpm.log.1245891191.gz" if gzipped.
>
> >
> > > Also you could use logrotate but I think this
> > usually runs once per day, not positive on that.
> > Then logrotate would keep 3 logs and rotate only
> > if size is over 100MB.
> > >From my research, I think you're right that it's
> > once daily.
> >
> > Thanks,
> > Pierre
> >
> > --
> > Pierre Far, PhD
> > pierrefar@gmail.com <mailto:pierrefar@gmail.com>
> >
> > Know before your site crashes:
> > http://SocialAlerter.com/
> > Webmaster and SEO resources: http://ekstreme.com
> > Blog of Science: http://blogsci.com
> > Short URLs with analytics: http://cli.gs/
>
> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?3,3333,3345#msg-3345
>
>
Jim
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 254
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready