PHP from scheduled task can't see folders, CLI works

Here is our setup:

Server A - Windows 2008 R2
PHP script on server A that copies files

Drive O: on computer B - Windows computer
contains source files

Drive V: on computer C - Debian Linux computer
target folder

We have the PHP script on server A that copies files from the mapped drive O: (on computer B) to the mapped drive V: (on computer C). The script works perfectly when run manually from the command line.

However, when the same PHP script is run from Task Scheduler it can’t see the folders on drive O:. I had it echo out is_readable and is_writable on the O: drive folders, and when run from CLI they both return 1 but when run from task scheduler they return 0. I also had both echo out get_current_user and they both return the same user.

The scheduled task is set to the same user the CLI one is, and is set to run with highest privileges.

The scheduled task calls a batch file that then calls the php file. This is the contents of the batch file:

@echo off
start “” /b /separate php -f “d:\scripts\get_files.php”

If I run the batch file manually the script works, so it definitely seems to be something with the scheduled task itself, but I can’t figure out what. Any help would be greatly appreciated. Thank you!

You can’t used mapped drives, unless you stay logged into the machine…

Switch over to unc paths…

After a lot of testing I eventually figured it out. It turns out when a scheduled task runs another program, all mapped drives become “unavailable” to the program. You have to “re-map” the drives when the program runs in the context of a scheduled task.

I had the PHP script do:

[php]
$cmd = ‘net use > net_use.txt’;
exec($cmd);
[/php]

and every mapped drive has a status of “unavailable” when run as a scheduled task, but status of “Ok” when run directly from the command line. If I re-mapped the drives (or mapped new drives to the same paths with different drive letters) when run as a scheduled task the script worked.

Sponsor our Newsletter | Privacy Policy | Terms of Service