I have a rather interesting problem. I use FileZilla and Notepad++ to edit my PHP scripts. One script, called functions.php, is edited and changed a lot. Unfortunately, everytime I edit it and reupload it, I check my error log and find that about 5 errors were thrown across my site every time I reupload. It only takes a few seconds, but since the script is included in about every page on my website, that few seconds is enough to throw errors.
I was thinking that, perhaps, I could have a functions2.php that would be basically the same. Would there be a way for the scripts on my site to grab functions2.php if functions.php is not available? Thanks.
EDIT: The error I get is usually something like “Parse error: syntax error, unexpected $end…” which I believe implies that the script is just partially uploaded. This might make file_exists not the best solution, since the file is THERE but it is only ‘halfway’ there.
Uploading and renaming seems like a good solution, but it is a bit tedious for every upload 🙂 I reupload and test a lot.
Is there a way to check a php file for PHP syntax errors? This would be quite handy in thise case…
Instead of using FTP, consider a PHP / Perl / Ruby script that will take a POST of the file being uploaded, along with the file name and a MD5 / SHA of the file to be replaced (to make sure you have everything in the post). You need to add some security as well, such as behind an Apache Login.
Once the posted file is accepted by the PHP / Perl / Ruby script, the md5 checked (and the security passed too), the server will overwrite the “old” with the “new” version. This should be a lot quicker than FTP and reduce the errors.
Only possible issue is the file permission on the server will need to be set to allow write access from the web server.
Just an idea.
Another idea…
mv /staging/<file> ./You could have a cron job perform this once an hour too, maybe.