-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathping.php.example
35 lines (26 loc) · 946 Bytes
/
ping.php.example
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
<?php
/**
* @file
* Example ping script.
*
* This script is intended to be used as a starting point to copy and
* adapt to your needs.
*/
define('DRUPAL_ROOT', '/path/to/drupal');
// Prevent sql injection.
$timestamp = $_GET['timestamp'];
if (!is_numeric($timestamp)) {
die();
}
// Connect to drupal database.
require_once DRUPAL_ROOT . '/sites/default/settings.php';
$creds = $databases['default']['default'];
$constr = sprintf("%s:dbname=%s", $creds['driver'], $creds['database']);
$db = new PDO($constr, $creds['username'], $creds['password']);
// Get count of new items.
$result = $db->query("SELECT count(nid) FROM node WHERE created > $timestamp");
// HTTP headers to prevent caching the result of this call.
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past (HTTP 1.0)
// JSON response.
print '{"pong":"' . $result->fetchColumn() . '"}';