Making a Push Notification Server

We had a need to test locally an endpoint of a SaaS Push Service. We did not want to rely on the SaaS for testing, so we needed a way to generate an equivalent push locally. This method requires a PECL extension, pecl_http. On a side note, I had to download the PHP source files to my MAMP installation, but that’s another story.

Once pecl_http was installed, it was very easy.

$data = $_POST['data'];
$info = '';
$response = http_post_data('http://localhost/path/to/endpoint', $data,array(0,$info));
echo $response;
<form action="#" method="post">
<textarea name="data" rows="10" cols="40"><?php echo stripslashes($_POST['data']); ?></textarea><br />
<input type="submit"></input><br />

Its as easy as that. You can serialize, json, xml, your data before you send it, then interpret it when you receive it. Of course, be sure to santize your inputs!

Leave a Reply

Your email address will not be published. Required fields are marked *