SOURCE CODE: https://github.com/pubnub/pubnub-api/...
The PHP program file is 70 lines and is easy to read through. This is a great demonstration of using PubNub PHP Client API. PHP Chat program was simple to build. Starting with STDIN to capture the user's screen name. Following with a connection to the PubNub server using the $pubnub->subscribe() PHP API function.
We are using pcntl_fork() command to let our subscribe process run as a child. All incoming data gets printed to the same STDOUT and we are not blocked by waiting for a message. We can send messages even while the subscribe process is listening.
To capture User Input we block on input in the parent process using trim(fgets(STDIN)). When the user presses Enter, a tick forward in the code captures typed text on the screen and allows us to execute the $pubnub->publish() api call. This sends the message to any connected users listening at the same time.
PHP Command Line Interface (CLI) and Server Push API Walkthrough pubnub.com/blog/php-push-api-walkthrough will bridge the gap between your JavaScript Browser (like Firefox) and PHP on the command line or in your server application using Apache, NginX, lighttpd and more.
Visit the home website of PubNub at pubnub.com to use our JavaScript API which works with iPhone and iPads!