将数据从服务器推送到用户浏览器
2022-08-30 20:06:22
我想将数据从服务器推送到浏览器。我已经知道发送输出缓冲区的php函数。我需要一些逻辑方面的帮助。我正在使用Facebook实时API,所以我想在每次Facebook访问我的网站时将数据推送给用户。ob_flush()
这是我的代码,我试图将数据推送到浏览器,但它不起作用。
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/event-stream');
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
error_log( "LOGS STARTS FROM HERE" );
if(isset($_GET['hub_challenge'])){
echo $_GET['hub_challenge'];
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
$updates = json_decode(file_get_contents("php://input"), true);
// Replace with your own code here to handle the update
// Note the request must complete within 15 seconds.
// Otherwise Facebook server will consider it a timeout and
// resend the push notification again.
print_r($updates);
ob_flush();
flush();
//file_put_contents('fb.log', print_r($updates,true), FILE_APPEND);
//error_log('updates = ' . print_r($updates, true));
}
?>