Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 773989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:03:22+00:00 2026-05-14T19:03:22+00:00

I created a question on serverfault.com, and it was recommended that I ask here.

  • 0

I created a question on serverfault.com, and it was recommended that I ask here.

https://serverfault.com/questions/140669/why-cant-php-script-write-a-file-on-server-2008-via-command-line-or-task-schedul

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:03:23+00:00Added an answer on May 14, 2026 at 7:03 pm

    Most likely you need to specify an absolute path to your feed file. It’s not clear exactly where you’re executing the script from, but the script’s “working directory” is generally where it was started from:

     c:\some\deeply\nested\directory> c:\php5\php.exe d:\inetpub\tools\build.php
    

    will be trying to write the feed file in:

     c:\some\deeply\nested\directory\feed.xml
    

    and not in c:\php5 or d:\inetpub\tools

    I don’t know what the task scheduler uses as its default directory, but most likely it’s not what you’re expecting.

    Also check that the account you’re running the job under in the task scheduler has write permissions on the output directory. And always check if an fopen() called succeeded (it returns FALSE on failure).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.