Question

I have a CLI PHP script running on an OSX system that saves files to a connected NAS drive. If the NAS is unmounted then remounted, the file_put_contents() function fails and returns the error:

Warning: file_put_contents(/Volumes/XXX/XXX.file) [/phpmanual/function.file-put-contents]: failed to open stream: No such file or directory

I'm clearing the file cache with clearstatcache() before the write. The drive is clearly mounted.

Restarting the script does not help. The only thing so far that works is to restart the machine.

Anyone have any thoughts on how to get PHP to 're-recognize' the connected volume?

Was it helpful?

Solution

After some serious digging, I figured out that it has to do with the filesystem and not PHP. I solved it by running the following commands:

exec('mkdir /Volumes/Mount_Point;
    mount_afp afp://user:pass@192.168.0.X/Mount_Point /Volumes/Mount_Point');

This re-establishes the necessary link(?) so that the PHP script can read it again. Re-mounting it from the Finder did not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top