We have a problem when uploading PHP files to our production NFS server where we start getting PHP parse errors after uploading them. The only way to "fix" them, is to open them with vim and save without making any changes through SSH. This makes me think it might be related to the file encoding. I can't seem to find any info on how to fix this anywhere.

We use FileZilla to upload the files through SFTP.

Things we have tried so far:

  • Checking everyone is editing the files with UTF-8 without BOM encoding.
  • Changing FileZilla's file transfer type to binary (if using SFTP, transfer type is always binary).

Example errors:

ParseError: Uncaught exception 'ParseError' with message 'syntax error, unexpected '} '' in XXXXXX.php:XXXX

Uncaught exception 'ParseError' with message 'syntax error, unexpected ''] = '' (T_CONSTANT_ENCAPSED_STRING)' in XXXXX.php:XXXX

Server info: AWS EC2 Instance running NFS. The NFS is used by multiple auto-scaling instances running Apache and PHP7 with OPCache enabled.

  • Have you compared a freshly uploaded file to the 'fixed' version of the same file?
    – Bert
    Sep 9 '20 at 13:50
  • @Bert We tried comparing them and they are the same, though we haven't checked any hidden characters. I'll make sure to take a look next time it happens and edit the OP.
    – ncorral
    Sep 9 '20 at 14:01

This is speculation on what might be causing it. I don't know NFS internal operations well enough to accurately describe issues, but I'm giving out educated guesses.

This could be a file locking / synchronisation issue. PHP process might read an incomplete PHP file from the NFS server during the upload, triggering the error. NFS client doesn't realise that the file has changed when upload is completed, so it still uses the incomplete file from client system cache.

When you edit the file and save it, the editor reads and writes it in one atomic operation. NFS client now sees that the file status has changed and reads it from server.

You could try using noac option in the NFS client mount command to disable file attribute caching. Another alternative is to use actimeo=3 to set cache time to 3 seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.