Page 1 of 2
Problem in wget in php script
Posted: Thu Oct 18, 2007 11:37 pm
by abhijeetgk
hi
in my application there is one section of code where i m trying to get the content via "wget" command.
for normal wget command on unix prompt it is working properly ie "wget
http://domainname.com/path_to_file"
but for the script it is giving me error of unable to resolve host name.
is this the problem of linux server of code.
please guide me on the same
thanks in advance
Posted: Thu Oct 18, 2007 11:48 pm
by aaronhall
Have you checked that the domain is valid? You can try using file_get_contents() instead, but you're probably calling a domain name that doesn't exist.
it is correct
Posted: Fri Oct 19, 2007 12:03 am
by abhijeetgk
hi
the domain name is correct
for the same domain name i can get the same content in browser correctly
Some more details of the problem are as-
In the application i m passing some parameters along with the url and depending on that parameters i m generating one output file
the contents of that file is mailed to user.
The contents of the url along with the parameters were generating correctly in browser but when i m trying to get that output in one file to mail the user then the output file is showing 0 k ie no content.
Posted: Mon Oct 22, 2007 3:35 pm
by feyd
I suspect the site serves different content to different browsers based on their user-agent string. It probably doesn't recognize the one PHP or wget is giving it.
Posted: Mon Oct 22, 2007 3:42 pm
by VladSun
feyd wrote:I suspect the site serves different content to different browsers based on their user-agent string. It probably doesn't recognize the one PHP or wget is giving it.
abhijeetgk said that "for normal wget command on unix prompt it is working properly", so it could not be this.
@abhijeetgk - have you tried to execute wget with your Apache user? And post your shell exec script, please.
Posted: Mon Oct 22, 2007 4:09 pm
by neophyte
I might add if Feyd is correct it is really easy with wget to use a different user-agent.
Posted: Mon Oct 22, 2007 4:20 pm
by shannah
If you post a snippet of your code, perhaps we can gather some more clues as to the reason why you are receiving this error.
Problem in wget
Posted: Mon Oct 22, 2007 11:36 pm
by abhijeetgk
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi
the command i m using is as follows in the script
with this all the paramenters substituted i m getting the proper output in the browser
but with this i m gettin the output "$tmpfname" as blank ie "0k"
Code: Select all
system("wget -c 'http://$HTTP_HOST/chiefSecretary/meetingNoticeSubmit.php?". "meetingId=$meeting_inst_Id&meetDay=.$meetDay&meetMonth=". "$meetMonth&meetYear=$meetYear&lang=$lang&langUCase=$langUCase&dept=$dept' -O $tmpfname");
.
.
.
.
$fd = fopen($tmpfname, "r");
$data = fread($fd, filesize($tmpfname));
while executing this i m gettin the error as the filesize is 0k
please suggest me solution
thanks
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Oct 23, 2007 4:05 am
by VladSun
Have you tried any simple downloads. I.e.:
Code: Select all
system("wget 'http://forums.devnetwork.net' -O $tmpfname");
Does it work?
Also add "-o logfile.log" option to the command line to see what happens.
problem in host resolving
Posted: Tue Oct 23, 2007 4:47 am
by abhijeetgk
hi
In the log file as suggested i added the output file, but in that following error occured
Resolving ................failed host not found
but i would like to mention here once again that the same url worked properly in the browser
is this some unix related issue or php related issue ?
thanks
Posted: Tue Oct 23, 2007 5:12 am
by VladSun
VladSun wrote:@abhijeetgk - have you tried to execute wget with your Apache user?
VladSun wrote:Have you tried any simple downloads. I.e.:
Code: Select all
system("wget 'http://forums.devnetwork.net' -O $tmpfname");
Does it work?
Help me - help you

it is working
Posted: Tue Oct 23, 2007 5:27 am
by abhijeetgk
it is working properly
but how can i execute it with apache user in the script ?
Posted: Tue Oct 23, 2007 6:02 am
by VladSun
Code: Select all
sudo -u apache_user_here wget 'http...
same again
Posted: Tue Oct 23, 2007 7:38 am
by abhijeetgk
hi
thanks for the help but the problem still persists
what to do now................
Posted: Tue Oct 23, 2007 8:23 am
by VladSun
I meant to run this:
Code: Select all
sudo -u apache_user_here wget 'http://forums.devnetwork.net' -O temp.html
in bash shell, not from PHP script. Does it raise any errors?