note 121241 added to function.pg-get-notify

From: Date: Sat, 17 Jun 2017 20:12:26 +0000
Subject: note 121241 added to function.pg-get-notify
Groups: php.notes 
Request: Send a blank email to php-notes+get-209143@lists.php.net to get a copy of this message
Instant yet Simple PHP notification with HTML5 Server-Sent Events sse.php <?php $dbconn = new PDO("pgsql:host=localhost;dbname=mydb", "pduser", "userpass"); $dbconn->exec('LISTEN "channel_name"'); // those doublequotes are very important header("X-Accel-Buffering: no"); // disable ngnix webServer buffering header("Content-Type: text/event-stream"); header("Cache-Control: no-cache"); ob_end_flush(); // close PHP output buffering $inc=0; while (1) { $result = ""; // wait for one Notify 10seconds instead of using sleep(10) $result = $dbconn->pgsqlGetNotify(PDO::FETCH_ASSOC, 10000); if ( $result ) { echo "id: $inc\ndata: ".stripslashes(json_encode($result))."\n\n"; $inc++; } flush(); } ?> Tested with HTML+JS sample file from Mozilla web site (ssedemo.php) ---- Server IP: 72.52.91.14 Probable Submitter: 151.182.69.166 ---- Manual Page -- http://php.net/manual/en/function.pg-get-notify.php Edit -- https://master.php.net/note/edit/121241 Del: integrated -- https://master.php.net/note/delete/121241/integrated Del: useless -- https://master.php.net/note/delete/121241/useless Del: bad code -- https://master.php.net/note/delete/121241/bad+code Del: spam -- https://master.php.net/note/delete/121241/spam Del: non-english -- https://master.php.net/note/delete/121241/non-english Del: in docs -- https://master.php.net/note/delete/121241/in+docs Del: other reasons-- https://master.php.net/note/delete/121241 Reject -- https://master.php.net/note/reject/121241 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209143) next »