This repository was archived by the owner on Apr 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathping.php
More file actions
60 lines (49 loc) · 1.36 KB
/
ping.php
File metadata and controls
60 lines (49 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* heroku-ping-php
*
* PHP script to ping your Heroku apps to keep them awake
*
* @package heroku-ping-php
* @author Dan Chen
*/
// add Heroku app urls
$sites = array('http://myapp.herokuapp.com/', 'http://myapp2.herokuapp.com');
// ----------------------------------------------------------------- //
$handles = array();
foreach ($sites as $i => $url) {
$ch = $handles[$i] = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
}
// create the multiple cURL handle
$mh = curl_multi_init();
// add the handles
foreach ($handles as $ch) {
curl_multi_add_handle($mh, $ch);
}
$active = null;
// execute the handles
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
// close the handles
foreach ($handles as $ch) {
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);
// write to log
// you can check this script is being run by running:
// heroku logs -t
error_log('Completed at ' . date('r'));