12-10-2009
[PHP] Script to Time Remote Server Response and Email
Here is a simple PHP script I wrote that times getting a link using mtime with curl and emails if it does not meet my objective. I use it in production for checking the performance of a Content Delivery Network (CDN), but you can use it for any web server.
PHP Code:
<?php
$heartbeat = "your.remote.server.com/file.html";
$delay = 2500;
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $heartbeat);
// header
curl_setopt($ch, CURLOPT_HEADER, 1);
// connection timeout
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $delay);
// store results as the return of curl_exec
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// curl timeout
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $delay);
// if HTML error 400 over over, fail
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
// set start time
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$output = curl_exec($ch);
//set end time
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
curl_close($ch);
$pattern = '/Your_Pattern/';
$errno = preg_match($pattern, $output, $matches, PREG_OFFSET_CAPTURE);
if($errno == 0){
$to = "your.email@yourdomain.com";
$subject = "Problem with Server";
$body = "There is a problem with the Server\n\n";
$body .= "This script executed in " .$totaltime. " seconds.";
$header = "From: root@yourdomain.com\r\n";
$header .= "Reply-To: root@yourdomain.com\r\n";
$header .= "Return-Path: root@yourdomain.com\r\n";
$success = mail($to, $subject, $body, $header);
}
?>
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I would like to know if there is a way to get the date and timestamp of the file that is being FTP from the remote server using shell script. Currently the get command from FTP will have current date and timestamp. Tried the earlier suggestion 'HardFeed' but still getting the current date and time... (12 Replies)
Discussion started by: gthokala
12 Replies
2. Shell Programming and Scripting
Hi,
Im creating a script that is supposed to run commands on remote server using sftp.
My script is as below:
#!/bin/ksh
sftp remote_server
mypassword
cd /u08/mydir/allfiles
mget *
..
But this is what I got when I runned the script:
Connecting to remote server...... (3 Replies)
Discussion started by: luna_soleil
3 Replies
3. UNIX for Dummies Questions & Answers
Hi,
i dont have remote m/c user credential. i only know remote m/c ip address. and i am able to ping that remote m/c.
In windows we use: "net time \\computername" to get the remote m/c time.
so how can i get remote m/c time in unix m/c? (means a unix command)
Thanks for the help.
... (9 Replies)
Discussion started by: partha_ori
9 Replies
4. Shell Programming and Scripting
hi,
I am using the below line to run a script from remote server(say server A) to another server(say server B).
ssh username@servername ksh script name.
The issue is the script logs into server B, executes the script on server B, transfers the file to server A but does not exit from... (4 Replies)
Discussion started by: yohasini
4 Replies
5. IP Networking
Hi everyone!
How can I get response time difference between GET and HTTP/1.0 200 OK (i mean time latency of web-server) with using of tshark&shell or something else for each hostname from pcap file?
What can you recommend me to do that? (1 Reply)
Discussion started by: lepetal
1 Replies
6. Solaris
Hi,
I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script.
Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies
7. Shell Programming and Scripting
Hi guys,
So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies
8. Shell Programming and Scripting
Hi,
My goal is to monitor the response time from the access logs of nginx server. I am using gawk to print the needed fields - 'response time' and 'name of the service' from nginx logs.
Command: gawk '($6 ~ /cloudservice/) {print $10, $6}' access.log
Output:
0.645 /nc/cloudservice... (6 Replies)
Discussion started by: nshah11
6 Replies
9. Shell Programming and Scripting
I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code
TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies
10. Shell Programming and Scripting
Hello all,
I am using the VPN provider Private Internet Access.
I am using the Raspberry Pi 4 with 4GB of RAM, performance on this upgraded board is great.
Anyways I am connecting to its service using systemd's openvpn-client @ US_New_York_City.service
I wonder if I can create a... (5 Replies)
Discussion started by: haloslayer255
5 Replies