Advertisement

Sending HTTP request on console

Started by November 19, 2004 04:32 PM
5 comments, last by 41ph4_r4p70r 20 years ago
I'm trying to send an HTTP request by console. I have a php script, so I need to call it several times,so, I have a little bash script that does the job, the problem is, I dunno how the hell to call it from console. I tried the GET (from lwp-request) but that doesnt seem to work (the variables are never sent to the php script) Is there any other way to accomplish this (console only) I tried graphically with opera and firefox, and their "reload page every XX second" to call the php script recursively, but after a while, both browsers seem to give up and wont reload anymore, thats why I wanna do it on a console thx
Your best bet is to use the command-line version of PHP and run the script directly (not via the web server).

This will give you more control - for instance, the maximum timeout is usually disabled.

Mark
Advertisement
mmmm, no, when I said "I have a php script" I meant more like a friend o' mine has one. In the end, I dont have access to the contents of the script, I just need to call it several times, and the script is localted on a server I dont own
Wget should work, depending on how the script works. Just loop it in a shell script or use some kind of cron implementation for it. Maybe even wget has some built in functionality for this.
What exactly is the PHP script doing, and do you need to see the results, or just call it? You can easily write a small application that will simply send an HTTP request, receive the data and do nothing with it. I have written VB apps to request web pages via the net, and receive the page data (and process a few things on it). You could simply put something like this into a program, and put it on a timer. Just look up HTTP protocol, and you'll find out the header you must send, it's pretty simple, something like: GET directory/file.php HTTP/1.0 (2 enters afterwards).

I'm not sure if that's the exact syntax, but it's very similar to that.
if you have a working bash script, you can run it repeatedly with 'watch', for example, to run it every 60 seconds, do this:

$ watch -n 60 ./your_script.sh

and this will keep running it until you stop it.

If you want to run it in a permanant fashion, use cron, for example to run it every 15 minutes as user 'bob' forever, add this to /etc/crontab:

*/15 * * * * bob /path/to/your_script.sh


HTH,
-g
Advertisement
Just for the record, I did it (like last saturday).

Leffe : wget doesnt work well with php scripts, so It wasnt a viable option

Ready4Dis : Yeah, I used a nice little java class called URL :) that sends a request to a server, and I can get the contents returned by the php script through an inputstream.

grazer: nice *nix commands, je je

This topic is closed to new replies.

Advertisement