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

  • SEARCH
  • Home
  • 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 7721247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:52:32+00:00 2026-06-01T03:52:32+00:00

I can’t get wget to work when called from PHP through exec() . The

  • 0

I can’t get wget to work when called from PHP through exec().

The code is:

exec('wget -b --timeout=300 --no-check-certificate -O c:\wgetlog.txt http://localhost/project/someparam/somevalue > c:\wgetout.txt')

The called URL is an action from a project based on Zend Framework that manipulates some data in a MySQL database.

When the above is executed, only “c:\wgetout.txt” is created, and is empty.

The setup is as follows:

  • Windows 7
  • XAMPP
  • PHP ver 5.3.5
  • wget latest version from here
  • PHP safe_mode is Off

wget is installed in “C:\Program Files (x86)\GnuWin32\bin”, and this is added to the Windows PATH variable.

I know the wget setup is working because when running the above exec parameter (as echoed)

wget -b --timeout=300 --no-check-certificate -O c:\\wgetlog.txt http://localhost/project/someparam/somevalue > c:\\wgetout.txt

in a command prompt, it runs fine, I get the expected results in the database, and both files “C:\wgetlog.txt” and “C:\wgetout.txt” are created, with the latter containing wget’s output (process id, etc).

LATER EDIT:

Got it working thanks to Crontab’s suggestion and used the absolute path for calling wget, also enclosed it in double quotes.

Used WSH COM object to run it instead of plain exec().

Also, on Windows, the -b parameter doesn’t work if the output isn’t directed somewhere. As I’m not particularly interested in the output, I directed it to > NUL 2>&1 (this includes errors also).

I quickly made this function to help me test my project on a Windows machine and have wget working, so here it is, in case anyone finds it useful:

public function execWget($URL, $intTimeout = 30, $blnInBackground = true) {
    if (preg_match("/Win/i", PHP_OS)) {
        $runCommand = '"C:\Program Files (x86)\GnuWin32\bin\wget" ' . ($blnInBackground?'-b ':'') . '--timeout=' . (int)$intTimeout . ' --no-check-certificate ' . $URL . ($blnInBackground?' > NUL 2>&1':'');
        $WshShell = new COM("WScript.Shell");
        $oExec = $WshShell->Run($runCommand, 7, false);
    } else {
        $runCommand = 'wget ' . ($blnInBackground?'-b ':'') . '--timeout=' . (int)$intTimeout . ' --no-check-certificate ' . ($blnInBackground?'-O /dev/null ':'') . $URL . ($blnInBackground?' > /dev/null 2>&1':'');
        exec($runCommand);
    }
}

Please mind that it’s customized for my own setup (absolute path to wget), it’s for testing purposes only (only use the Windows machine for testing, the actual production machine runs Linux), the OS checking method might not be the best, etc.

  • 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-06-01T03:52:34+00:00Added an answer on June 1, 2026 at 3:52 am

    Try using an absolute path to wget – it’s probably not in your script’s path. To avoid using the absolute path, you could try adding putenv("PATH=<whatever-paths-you-need-colon-delimited>"); in your script before you access wget. Another way would be to directly modify the PATH environment variable of whatever user is running your webserver (and hence whichever user runs the PHP interpreter).

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

Sidebar

Related Questions

Can somebody tell me how to get mod_rewrite to rename this: our-work-section.php?id=3&title=something to our-work-section/something/3
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can i get the source code for a WAMP stack installer somewhere? Any help
Can you cast a List<int> to List<string> somehow? I know I could loop through
Can I get a 'when to use' for these and others? <% %> <%#
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can a Visual Studio 2008 custom tool be passed additional parameters from the custom
Can anyone tell me what i am doing wrong? I am trying to get
Can some one Guide me to work with these things... What is Model popup

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.