Fairly new to the linux world and I have some questions/concerns about a network mount being used with a php web app. I am mostly looking for some best practice advice on using network mounts with php as this is my first experience and I want the best performance I can get.
The mounts I want to perform will be from linux machines to windows machines. There are a variety of operating systems. Ubuntu Mate,Raspbian Jessie needs to mount to folders on Windows 7,10
My app will be creating some thumbnail image files to save on a network folder as well as accessing some mp4 vids for playback. In addition, I need to create one html file at startup. I will have two mounts that need to be accessed periodically throughout the day and one mount just at startup.
One Raspberry Pi3B running ubuntu mate will grab vids to create thumbnails for them, this pi will also make the html file I need just at startup. I planned to use php to handle those tasks but need a solid way to mount the folder.
A second Raspberry Pi3B running raspbian jessie will later access those same vids for display on a webpage.
The app will work in this order. First, making an html page, next create thumbnails, and later advance the user to view the vids.
Previously I experimented and I was able to mount one of the network folders. I used a command in fstab. It fired at startup which I assumed as what I wanted. However....
This establishes a continuous mount from what I know and seems excessive because the app will only be used periodically throughout the day with a small staff. Thus, I do not need these mounts to continue all day. I would rather they only be mounted on an as needed basis.
One issue, even with the mount statement above, is the IPs for the machines with the mounted network folders can change. They are not static and I can not fiddle with the network.
I used nmap, piped the results into a php script and now can get the IPs of the two machines I want to connect with. My thought is to store the IPs in a database and use it to mount the folders I need when I need them.
My primary question here is how to call my mount commands with dynamic IPs when I need them and close them when finished.
Through research I have identified a few ways I think I could do this but wanted to clarify with anyone else about any other options and best practice.
- I assume I could call mount statements from exec() or shell_exec() in php. Mount the folder at beginning of the php script and close it at the end.
Perhaps this is slower? Is this bad?
- I recently bumped into autofs while researching. This sounds like basically the same idea as #1 but perhaps a bit more better in case of error type situations where one machine might be offline for some reason. I am unclear on use with php or if it is better. Posts about it say that after setup and configured "Devices are now automatically mounted when they are accessed, they will remain mounted as long as you access them."
https://wiki.archlinux.org/index.php/Autofs
I assume folders would be automatically mounted if accessed through command line arguments but would this extend to a call to the folder via a php script?
Some combination of the 1-2?
Access it directly by using something like... \xxx.xxx.xxx.xxx\SharedFolder\fileIwant.ext
Something else?
Does anyone have experience with php and network mounts? Any feedback on these approaches?
UPDATE I ended up making a bash script that has the mount statement, editing the sudoers file to allow the script to be called with sudo priveleges, and calling the bash script through php exec. I have one for mount and unmount. I call to check if there is a mount and if not mount the folder. Then on logout I call the unmount script to unmount. This is probably very roundabout and may use more resources than I should but it works.