I'm having difficulties believing this question hasn't been asked before, but I couldn't find anything relevant.
Occasionally, when uploading a rather large PHP script, I receive a fatal error similar to something like:
Parse error: syntax error, unexpected $end in [file] on line [line]
A quick refresh later and the error of course disappears as the upload completes. A simple solution is to switch my FTP client's transfer mode to binary, but that seems a bit strange as the script is ASCII.
I'm accustomed to uploading ASP.NET files over plain text, where the server simply waits until the transfer is complete before delivering the page.
What's best practice?
You should transfer your scripts to a staging directory on your server and use ftp move commands to move them live after they have been properly tested in staging.
The script is breaking because not all of it is on the server, so the file ends in themiddle of the script. You should just be patient and wait for it to upload. If you are in a situation where you will be during this while the server is live and the users will be accessing this page (I honestly can't think of when that would ever happen) you could just change the permissions so it's not readable by the web server while it's uploading and then fix the permissions after it's loaded.
If you're deploying scripts to a live environment you may wish to consider using rsync
.
It's far quicker than FTP because it compares both the target and the source first and only moves files that are newer in the source location. It should also remove the issues you're experiencing with the large PHP sripts not completely uploading.
As an alternative, you could use rsync to move files from your source target location up to a test directory on the target web server. Once this has complete, you can trigger an rsync on the live web server to sync files from the test directory to the live. The advantage here is that the second rsync would be instantaneous almost, further reducing the time that files are being overwritten.
Of course, rsync
is only available in on linux servers, but robocopy could be utilised to a similar effect on a windows environment