Why can’t PHP script write a file on server 2008 via command line or task scheduler?
Posted
by rg89
on Stack Overflow
See other posts from Stack Overflow
or by rg89
Published on 2010-05-11T15:36:54Z
Indexed on
2010/05/11
17:24 UTC
Read the original article
Hit count: 197
I created a question on serverfault.com, and it was recommended that I ask here.
I have a PHP script. It runs well when I use a browser. It writes an XML file in the same directory. The script takes ~60 seconds to run, and the resulting XML file is ~16 MB.
I am running PHP 5.2.13 via FastCGI on Windows Server Web edition SP1 64 bit.
The code pulls inventory from SQL server, runs a loop to build an XML file for a third party.
I created a task in task scheduler to run c:\php5\php.exe "D:\inetpub\tools\build.php"
The task scheduler shows a time lapse of about a minute, which is how long the script takes to run in a browser.
No error returned, but no file created.
Each time I make a change to the scheduled task properties, a user password box comes up and I enter the administrator account password.
If I run this same path and argument at a command line it does not error and does not create the file.
When I right click run command prompt as an administrator, the file is still not created. I get my echo statement "file published" that is after the file creation and no error is returned.
I am doing a simple fopen fwrite fclose to save the contents of a php variable to a .xml file, and the file only gets created when the script is run through the browser.
Here's what happens after the xml-building loop:
$feedContent .= "</feed>";
sqlsrv_close( $conn );
echo "<p>feed built</p>";
$feedFile = "feed.xml";
$handler = fopen($feedFile, 'w');
fwrite( $handler, $feedContent );
fclose( $handler );
echo "<p>file published</p>";
Thanks
© Stack Overflow or respective owner