You'll find it easier to configure logrotate
to do the rotation for you. If you create a file called /etc/logrotate.d/php
containing something like the following, it'll handle the log rotation automatically. This is just a guide, so make sure to test and customise it before you put it into production.
/path/to/php.log {
daily
missingok # don't rotate if the file isn't there...
notifempty # ...or if it's zero-length
rotate 30 # keep 30 days' worth of logs
compress # gzip the logs, but...
delaycompress # ...only after they're over a day old
create 640 root adm # permissions with which to create new files
sharedscripts
postrotate
/etc/init.d/apache2 graceful # or whatever makes your process let go of the log file
endscript
}
NB: the comments in this extract break logrotate
syntax, so make sure to strip them out of your live config file.