1

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 Server 2008 64 bit.

I created a task in task scheduler to run c:\php5\php.exe "D:\inetpub\tools\something.php"

No error returned, but no file created.

If I run this same path and argument at a command line it does not error and does not create the file.

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.

Thanks

rg89
  • 143
  • 1
  • 7

1 Answers1

1

Permissions most likely. Try first to use the RUN AS Administrator option to launch the command prompt then see if that creates your file. If so then you know its just permissions.

What user is running the scheduled task? You will need to give that user proper permissions to write to the folder you would like to create the file in.

Do you have UAC turned on?

Campo
  • 1,609
  • 17
  • 33
  • Each time I make a change to the scheduled task properties, a user password box comes up and I enter the administrator account password. 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. UAC is on, and I only log into this machine as an Administrator using Remote Desktop. – rg89 May 11 '10 at 15:05
  • I also tried running the script from D: and C: to see if the drive or folder depth was the cause. I got some warnings earlier this week when I had open_basedir = d:\inetpub earlier this week, so I commented out that line in php.ini. – rg89 May 11 '10 at 15:08
  • Can you show us your script? Is this server part of a domain? – Campo May 11 '10 at 15:12
  • Sure, let me figure out the best way to put code into my replies. The server is part of a domain. 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. The task scheduler shows a time lapse of about a minute, which is how long the script takes to run in a browser. – rg89 May 11 '10 at 15:20
  • I believe the only part of the code that isn't working is the file creation. This is what happens after the loop: $feedContent .= ""; sqlsrv_close( $conn ); echo "

    feed built

    "; $feedFile = "feed.xml"; $handler = fopen($feedFile, 'w'); fwrite( $handler, $feedContent ); fclose( $handler ); echo "

    file published

    "; I tried tags. They didn't work. Sorry.
    – rg89 May 11 '10 at 15:20
  • You should put the code in your question :). I am not a programmer so I cannot help debug your code unfortunately, Maybe a question for stack overflow? – Campo May 11 '10 at 15:26
  • I voted it up hopefully others will join in and help you further. I feel its a programing issue. I will check in periodically or when there is action on this question. – Campo May 11 '10 at 16:02
  • i posted on stackoverflow, and i got a good answer there: http://stackoverflow.com/questions/2812057/why-cant-php-script-write-a-file-on-server-2008-via-command-line-or-task-schedul – rg89 May 11 '10 at 18:02