Forum Moderators: phranque

Message Too Old, No Replies

PHP Execution via Cron to hit web page

         

Cynthia Blue

2:33 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



This is my first post, looks like a nice site! I have a question...

I run my own web server with php where i host pictures and such for friends. Since it's not 100% reliable (due to what we think are power spikes that may keep frying our hardware :( ), I have another hosting service that runs my important website and forums.

On the important website and forums, I have added a program (phpAdsNew) that must have a php script run every hour. But, I don't have cron access to that server.

I'm wondering if I can set up my own web server to have a cron job that will run and excecute that php script on the other server ever hour.

Now I'm still new to servers and cron and such, and I'm not sure if I have PERL on my server (I run Suse Linux). Or what other method I could use to execute a program that will allow the remote php script to be hit every hour.

I appreciate any help! Thanks.

moltar

3:26 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, Cynthia!

If you have *nix OS on your server at home, you can simply add

wget
to your cron file.

wget -q -t 5 --delete-after http*//www.example.com/your.php

From wget manual:

-q: This option is the opposite of verbose, making Wget completely quiet. 

-t num: Set number of retries to num. Specify 0 or `inf' for infinite retrying.

--delete-after: This option tells Wget to delete every single file it downloads, after having done so. It is useful for pre-fetching popular pages through PROXY, e.g.

[edit reason]Added greeting[/edit reason]

[edited by: moltar at 3:28 pm (utc) on April 27, 2005]

rocknbil

3:26 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Edit: ^ ^ Well that's even better. :-)

Almost all servers have perl, but you could do a php equvalent of

$result = `curl [example.com...]
if (! $result =~ /<html>/i/) { &log("didn't work at $thisTime"); }
else { &log("Ran successfully at $thisTime"); }

where &log is a routine you have to log your cron requests, and $thisTime is a variable you previously created to store the server time in.

The backticks ` are an equivalent of "run this command," equivalent to perl qx"[command]" or semi-equivalent to perl system([command]).

If you set up cron_me.php to print out only a 1 when it runs sucessfully, you could do

if (! ($result == 1)) ....

You could use other methods than curl, as it only works on linux, but I think this will get you started toward a solution.

moltar

3:32 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



rocknbil - good idea about logging. You can do this with the following switch:

-a logfile: Append to logfile - the same as `-o', but appending to the logfile (or creating a new one if the old does not exist) instead of overwriting the old log file.

Cynthia Blue

3:35 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Excellent thank you very much! I will look into the options more and set something up. Seems fairly simple to do. Soon as we get the darn hardware fixed (probably a MB problem).