PHP API

The PHP Server API allows PHP application to send real-time messages via the PushFYI WebSocket gateway. The PHP API allow requests to be made synchronously.

PHP Server API has 3 main functions. In this documentation, we will examine the API usage and some of the best practices.

PushFYI - Interface Class

The PushFYI class is the entry point for any application to send receive real-time messages via the PushFYI WebSocket gateway. This class wraps all the necessary methods to send real time events.

This is not a singleton class and you can create more than one objects of this class.

Argument List:

SN parameters note
1 appsecret This parameter identifies your App when it connects to PushFYI. Since PushFYI can serve real-time messages to many apps simultaneously. This field allows PushFYI to distinguish between Apps, so that real-time messages from one App do not mix up with another App. The value of appsecret parameter is in UUID format. e.g. 123e4567-e89b-12d3-a456-426655440000
2 address URL of your pushfyi instance. e.g. http://10.0.0.101 for plain text connection and https://10.0.0.101 for secure connection.

Code Sample:


                            
require_once '../src/PushFYI.php';

$pushfyi = new PushFYI("<your appsecret key>",
          "http://<your pushfyi ip address>");

publish(channel, data)

The publish method allows a PHP application to publish a real-time message on a given data channel. PushFYI data channels are logical names to which realtime messages are sent to.

This method allows you to send a single message on a given data channel.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 data Array with key and value for single channel.

Code Sample:

                                                          
                           
require_once '../src/PushFYI.php';
 /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 * 
 */
$pushfyi = new PushFYI("<your appsecret key>",
          "http://<your pushfyi ip address>");
/*
 *Channel Name
 */
$channel = 'any_channel_name';
/*
 *	TWO DIFFRENT FORMAT TO SEND DATA
 *  Array with key and value for single channel
 *  FORMAT 1
 */
$data['name'] = 'pushfyi';
$data['message'] = 'single channel hello from pushfyi';

/*
 * FORMAT 2
 */
 
 $data = array("name" => "pushfyi",
                "message" => "single channel hello from pushfyi");

/*
 * publish message on single channel in Realtime
 * @param $channel
 * @param $data
 */
$response = $pushfyi->publish($channel, $data);

                        

publish(data)

The publish method allows a PHP application to publish a real-time message on multiple data channels. PushFYI data channels are logical names to which real-time messages are sent to.

This method allows you to send single message on multiple data channels.

Parameter List:

SN parameters note
1 data Array with key and value, key as channel and value as message.

Code Sample:

                                                      

require_once '../src/PushFYI.php';
 /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 * 
 */
$pushfyi = new PushFYI("<your appsecret key>",
          "http://<your pushfyi ip address>");
                                                    
/*
 * TWO DIFFRENT FORMAT TO SEND DATA
 * Array with key and value, key as channel and value as message.
 * FORMAT 1
 */
   $data = array();
   $data["channel1"] = array("name" => "pushfyi","message" => "multiple channel hello from pushfyi");
   $data["channel2"] = array('name' => "pushfyi","message" => "multiple channel hello from pushfyi");
   $data["channel3"] = array("name" => "pushfyi","message" => array("foo" => "bar","bar" => "24","multi" => array("dimensional" => array("array" => "foo"))));
   
/*
 * FORMAT 2
 */
   
   $data = array(
	    "channel1" => array(
	        'name' => 'pushfyi',
	        'msg' => 'multiple channel hello from pushfyi'
	    ),
	    "channel2" => array(
	        'name' => 'pushfyi',
	        'message' => 'multiple channel hello from pushfyi'
	    )
	);
/*
 * publish messages on multiple channels in Realtime
 * @param $data
 */
$response = $pushfyi->publish($data);