I've installed php-pushwoosh using composer at following location on my local machine :
/var/www/gomoob-php-pushwoosh
Now I want to send push notifications to iPhone through the PHP code.
So, I tried by myself and written PHP code in a file titled sample.php
which is located at /var/www/gomoob-php-pushwoosh/sample.php
. Following is the PHP code from file sample.php
Code Reference Link : You can get the code reference here
php-pushwoosh Installation reference Link : php-pushwossh installation reference link
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require __DIR__.'/vendor/autoload.php';
define('PW_AUTH', 'API TOKEN');
define('PW_APPLICATION', 'APPLICATION CODE');
define('PW_DEBUG', true);
function pwCall($method, $data) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' = $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print "[PW] info: " . print_r($info, true);
}
}
pwCall('createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => 'test',
'data' => array('custom' => 'json data'),
'link' => 'http://pushwoosh.com/'
)
)
)
);
?>
After executing this code into browser by hitting the URL localhost/gomoob-php-pushwoosh/sample.php
I'm getting blank page only, no errors, no warnings, no notices.
Why so? Can someone please correct the mistakes I'm making into my code by giving proper explanation and make my code workable?
If you need any further information regarding the issue I'm facing please do let me know.
If you have any kind of suggestion, comment, answer, criticism, etc. you are most welcome. any kind of help would be highly appreciated.
Thanks.
It's in this line:
$request = json_encode(['request' = $data]);
^
It should obviously be:
$request = json_encode(['request' => $data]);
You didn't see any notice because the display_errors
setting must be set outside of the script to catch parse errors such as this one.