
|
View Full Version : Refresh help
Danny159 12-22-2007, 07:16 PM Hi
Is there any way of refreshing a page without been on it? Like it will refresh every hour without a user on the page?
Danny
Codelphious 12-22-2007, 08:02 PM If a tree falls in the forest and there is no one there to hear it, does it make a sound?
If no one is viewing the page why would it need to update?
Danny159 12-22-2007, 08:12 PM because its for a stats page and say FTP crashed it would email me so it will need to refresh to send it.
Codelphious 12-22-2007, 08:21 PM I don't quite understanding what you're trying to do.
HTTP is a stateless protocol, meaning each time a page is requested it is fetched and sent to the client (e.g. browser) requesting it. If you're using a server side language to create the page, every time the page is requested the program to generate the page is executed and the page is sent to the client. Refreshing a page simply asks the server to resend the page. The content of the page may either be the same, or different, depending on the information the server side script decides to send.
If no one is requesting a page then it is irrelevant if the information on the server changed, and thus there's no reason for the server side script to generate it.
What you need to consider is implementing a database of some sort, to keep track of the information you need to send people that request it, then have a server side script pull that information from the database and create the page to send to the client that requests it.
azizny 12-22-2007, 09:06 PM I think you mean a cron job. A cron job is set to "refresh" itself on a specified time.
For example, I might have a cron job to start a PHP file that will check if my server is up, if it is not, it will email me a note, and this will refresh every 10 minutes.
Peace,
As azinzy suggested you should set up a cron job with
php /path/filename.php
futhey 12-22-2007, 11:53 PM Exactly, cron job is what you're looking for.
5 * * * * php path/to/myfile.php
Should do that trick. If not try
5 * * * * lynx -dump http://www.mysite.com/mypage.php
Danny159 12-23-2007, 05:30 AM Cool, so what is the
5 * * * *
for?
isurus 12-23-2007, 07:29 AM 5 * * * *Run at five minutes past every hour.... ie 1:05, 2:05, 3:05 etc etc.
Quoting man 5 crontab:
...snip...
The time and date fields are:
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
A field may be an asterisk (*), which always stands for ‘‘first-last’’.
Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an ‘‘hours’’ entry specifies execution
at hours 8, 9, 10 and 11.
Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: ‘‘1,2,5,9’’, ‘‘0-4,8-12’’.
Step values can be used in conjunction with ranges. Following a range with ‘‘/<number>’’ specifies skips of the number’s value through the range. For example, ‘‘0-23/2’’ can
be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is ‘‘0,2,4,6,8,10,12,14,16,18,20,22’’). Steps are also permitted
after an asterisk, so if you want to say ‘‘every two hours’’, just use ‘‘*/2’’.
Names can also be used for the ‘‘month’’ and ‘‘day of week’’ fields. Use the first three letters of the particular day or month (case doesn’t matter). Ranges or lists of names
are not allowed.
The ‘‘sixth’’ field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh
or by the shell specified in the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters,
and all data after the first % will be sent to the command as standard input.
Note: The day of a command’s execution can be specified by two fields — day of month, and day of week. If both fields are restricted (ie, aren’t *), the command will be run
when either field matches the current time. For example,
‘‘30 4 1,15 * 5’’ would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
futhey 12-23-2007, 07:35 AM Exactly right, isurus.
The main ones being:
*/# - Every # Hours(Minutes, etc.)
1,2,3 - series of numbers
0-3 - Range of Numbers
And of course:
* - All :)
I just picked an odd number (5) as a habit, so things aren't scheduled to be cron'd at the same time.
Danny159 12-23-2007, 07:58 AM would ths work?
http://img529.imageshack.us/img529/8501/jobqq1.jpg (http://imageshack.us)
isurus 12-23-2007, 02:45 PM The environment variables aren't the same when a script is run via cron versus you running it yourself - one of the differences is the PATH variable.
I would put in the full path to the php binary, eg /usr/bin/php (or whatever it is on your system:
[root@kermit ~]# which php
/usr/bin/php
futhey 12-23-2007, 09:30 PM Isurus: If you open the page via lynx, doesn't this solve that by running it through apache instead? Or do you mean it's different than running from the box you're on?
Or is there something I'm not understanding? haha.
Danny159: That should work perfectly, if your script would normally execute correctly when executed by the PHP Binary. If your script doesn't do anything fancy, It should work no problem. (I believe you said it just checks FTP and emails you if it's down, correct?).
Post if you still can't get it to work. (Maybe you could test it by having it send a 'FTP Working' email?)
Danny159 12-24-2007, 06:19 AM No it just checks to see if anything is down and if it is it will email me that its down... however the script needs to be ran to send the email it checks the following:
Apache
FTP
Email (POP3)
Email (IMAP)
Webmail
Cpanel
Internet Connection
WHM
SSH
DNS
:)
isurus 12-24-2007, 07:34 AM If you open the page via lynx, doesn't this solve that by running it through apache instead?Hi futhey, the issue was whether the system could locate the PHP binary (or the lynx binary) if it wasn't given the absolute path, not the effect that the different environment variables would have upon the functionality of the php script.
eg using "php" rather than "/full/path/to/php", or "lynx" rather than "/full/path/to/lynx" (or whatever) may not have worked.
$PATH when running manually (as root on my workstation):
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Default $PATH when running via cron (as root on my workstation):
/usr/bin:/bin
(You can add a PATH directive to your crontab)
If php is located in /usr/bin or /bin then just using "php" will work, but if you have installed php somewhere else on your system, eg /usr/local/bin, then the command will work when you run it manually, but fail when you try to run it via cron.
Personally I'd go for the lynx/wget approach....
azizny 12-24-2007, 09:52 PM If you are going to check for services, then write a bash/korn script as simple as 5 lines to check for server_array:
"server name status"
if the return is no OK, then email with that service.
Using PHP to check for services is not efficient (if done by minute), might not have exec rights or not accurate. For example when MySQL has over the limit, it won't connect through PHP, but would do via command line, but again, its a good idea to get notices of overloads.
Peace,
azizny 12-24-2007, 10:23 PM Here is a tested bash script that I just wrote:D:
#add/remove services you need
services=( httpd directadmin exim named proftpd vm-pop3d)
for service in ${services[@]}
do
export result=`service $service status`
if [[ ! $result =~ '.*running.*' ]]
then
echo "Service $service was detected to be down, response: $result"|mail -s "Service $service is down" "youremail@gmail.com"
fi
done
Not bad at all, I will be using it for my servers now on.
Peace,
Danny159 12-25-2007, 11:54 AM And what dose the above do?
Dan
azizny 12-25-2007, 02:53 PM And what dose the above do?
Dan
It is a bash script, you run it every 5 minutes and it will check the above services.
It is more efficient than using server side web scripting.
Peace,
|