Jump to content

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


raphael75

Recommended Posts

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!
 

Link to comment
Share on other sites

I did some more testing. In the batch file I put in:

 

dir O:\path\to\files > dir.txt

 

net use > net_use.txt

 

When I run the batch file manually both dir.txt and net_use.txt look right. However, when I run the scheduled task, dir.txt is empty and net_use.txt shows "unavailable" for the status of each mapped drive on the computer. What would cause the status to be "unavailable"?

Link to comment
Share on other sites

A little googling on windows task scheduler and mapped drives shows that drives are only mapped for interactive sessions, not background sessions used for running tasks.

 

If the drives do not require different credentials to be accessed, you can simply use a UNC path rather than map the drives:

copy('\\\\server\\path\\file.ext', '\\\\server2\\path\\file.ext');
Otherwise, you can map the drive from the script by calling out to the net use command first. Some potentially helpful reading: How to use Windows Task Scheduler to copy files from a server in another domain
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.