Problem in wget in php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

abhijeetgk
Forum Newbie
Posts: 9
Joined: Thu Oct 18, 2007 11:33 pm
Location: Mumbai
Contact:

Problem in wget in php script

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
abhijeetgk
Forum Newbie
Posts: 9
Joined: Thu Oct 18, 2007 11:33 pm
Location: Mumbai
Contact:

it is correct

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I might add if Feyd is correct it is really easy with wget to use a different user-agent.
shannah
Forum Newbie
Posts: 13
Joined: Mon Oct 15, 2007 1:01 am

Post 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.
abhijeetgk
Forum Newbie
Posts: 9
Joined: Thu Oct 18, 2007 11:33 pm
Location: Mumbai
Contact:

Problem in wget

Post by abhijeetgk »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
abhijeetgk
Forum Newbie
Posts: 9
Joined: Thu Oct 18, 2007 11:33 pm
Location: Mumbai
Contact:

problem in host resolving

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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 ;)
There are 10 types of people in this world, those who understand binary and those who don't
abhijeetgk
Forum Newbie
Posts: 9
Joined: Thu Oct 18, 2007 11:33 pm
Location: Mumbai
Contact:

it is working

Post by abhijeetgk »

it is working properly

but how can i execute it with apache user in the script ?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Code: Select all

sudo -u apache_user_here wget 'http...
There are 10 types of people in this world, those who understand binary and those who don't
abhijeetgk
Forum Newbie
Posts: 9
Joined: Thu Oct 18, 2007 11:33 pm
Location: Mumbai
Contact:

same again

Post by abhijeetgk »

hi
thanks for the help but the problem still persists

what to do now................
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply