0
我有两个文件,index.php和callback.php。 Index.php用于在网站上显示数据。 callback.php是一个充当监听器的脚本。 callback.php由服务器调用,并且callback.php中的$ update变量由服务器实时更新。我希望每次更新时都能看到$ update变量的内容。如何在充当监听器的脚本中查看变量的内容:Facebook实时更新
Callback.php:
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' &&
$_GET['hub_verify_token'] == VERIFY_TOKEN) {
echo $_GET['hub_challenge'];
} else if ($method == 'POST') {
$updates = json_decode(file_get_contents("php://input"), true);
//I want to see the content of $updates
// resend the push notification again.
error_log('updates = ' . print_r($updates, true));
}
我怎样才能做到这一点?请告诉我。如果您有一些示例代码,我将非常感激。
是的...这似乎有点我正在寻找。我的index.php提供了一些实时数据给服务器,回调url是callback.php。服务器将更改通知发送到callback.php。我想查看存储在$ updates中的更改通知。 – Praveen
当你说服务器端你是指服务器本身还是callback.php文件?我不控制将更改通知发送到callback.php的服务器。 – Praveen
你必须在服务器上有某种事件监听器。由于阻塞I/O,PHP通常不是侦听器的最佳解决方案。例如,如果您希望PHP脚本每秒钟检查数据库以查找来自其他用户的新帖子,则必须使用'sleep(1000)',这会暂停脚本并阻止其他脚本运行。这是NodeJS的主要优点之一。 – AlienWebguy