Telecharger Fichier Php Avec Wget Proxy

  1. Telecharger Fichier Php Avec Wget Proxy Environment
  2. Telecharger Fichier Php Avec Wget Proxy Example
  3. Telecharger Fichier Php Avec Wget Proxy Setting
  4. Comment Ouvrir Un Fichier.php Avec Xampp
  • Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange.
  • I am having trouble finding a way to use wget to download a file from a link that uses php to point to the download. For example, if I want to write a script to download. Say superantispyware.
Active7 years, 5 months ago

Wget supports proxy servers, which can lighten the network load, speed up retrieval and provide access behind firewalls. If you are behind a firewall that requires the use of a socks style gateway, you can get the socks library and compile wget with support for socks.

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)GnuWin32bin', 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:

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.

binar
binarbinar
1,0121 gold badge11 silver badges24 bronze badges

1 Answer

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).

CrontabCrontab
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Telecharger Fichier Php Avec Wget Proxy Environment

Not the answer you're looking for? Browse other questions tagged phpwindowsexecwget or ask your own question.

Liste de paramètres

filename

Nom du fichier à lire.

use_include_path

Note:

Telecharger

La constante FILE_USE_INCLUDE_PATH peut être utilisée pour déclencher la recherche dans le chemin d'inclusion. Ceci est impossible si strict typing est activé, car FILE_USE_INCLUDE_PATH est un int. Utilisez TRUE à la place.

context

Une ressource de contexte valide, créée avec la fonction stream_context_create(). Si vous n'avez pas besoin d'utiliser un contexte particulier, vous pouvez ignorer ce paramètre en affectant la valeur NULL.

offset

Telecharger Fichier Php Avec Wget Proxy Example

La position à partir de laquelle on commence à lire dans le flux original. Une position négative compte à partir de la fin du flux.

Telecharger Fichier Php Avec Wget Proxy Setting

Le déplacement dans le fichier (offset) n'est pas supporté sur des fichiers distants. Si vous tentez de vous déplacer dans un fichier qui n'est pas un fichier local peut fonctionner sur les petits déplacements, mais le comportement peut ne pas être attendu car le processus utilise le flux du buffer.

maxlen

Comment Ouvrir Un Fichier.php Avec Xampp

La taille maximale des données à lire. Le comportement par défaut est de lire jusqu'à la fin du fichier. Ce paramètre s'applique sur le flux traité par les filtres.