Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client->Post() hangs up PHP script #32

Closed
mfkrause opened this issue Dec 12, 2017 · 4 comments
Closed

Client->Post() hangs up PHP script #32

mfkrause opened this issue Dec 12, 2017 · 4 comments

Comments

@mfkrause
Copy link

mfkrause commented Dec 12, 2017

The post() function from the Client class seems to never return anything and keeps running. I'm trying this code (not much changed from the example):

	function sendPush($deviceTokens, $title, $body, $customValues = null, $badge = 1){
		$options = [
		    'key_id' => 'xxx', // The Key ID obtained from Apple developer account
		    'team_id' => 'xxx', // The Team ID obtained from Apple developer account
		    'app_bundle_id' => 'xxx', // The bundle ID for app obtained from Apple developer account
		    'private_key_path' => 'xxx', //Path to p8 key
		    'private_key_secret' => null // Private key secret
		];

		$authProvider = AuthProvider\Token::create($options);

		$alert = Alert::create()->setTitle($title);
		$alert = $alert->setBody($body);

		$payload = Payload::create()->setAlert($alert);

		//set notification sound to default
		$payload->setSound('default');

		if(isset($customValues) && $customValues != null){
			for($i = 0; $i < count($customValues); $i++) $payload->setCustomValue($customValues[$i][0], $customValues[$i][1]);
		}
		if($badge != -1) $payload->setBadge($badge);

		$notifications = [];
		foreach ($deviceTokens as $deviceToken) {
		    $notifications[] = new Notification($payload,$deviceToken);
		}

		$client = new Client($authProvider, $production = false);
		$client->addNotifications($notifications);

		echo(1);

		$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

		echo(2);
		
		foreach ($responses as $response) {
		    $response->getApnsId();
		    $response->getStatusCode();
		    $response->getReasonPhrase();
		    $response->getErrorReason();
		    $response->getErrorDescription();
		}
	}

As you can see, I've put two debug echoes before and after the push() function. While the 1 gets printed, the 2 doesn't. When I try to echo $responses, I get NULL, too, so it seems like it fails to get a response from the servers.

The push notification gets sent successfully though, it's just that I can't do anything after sending the push.

@edamov
Copy link
Owner

edamov commented Feb 10, 2018

@mfkrause Is this issue actual at the moment?

@tradingstratagem
Copy link

tradingstratagem commented Sep 21, 2018

Same problem here.
I have the following error:

PHP Notice: Undefined offset: 1 in /vagrant/vendor/edamov/pushok/src/Client.php on line 122
PHP Stack trace:
...
PHP 6. Pushok\Client->push()
PHP Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in /vagrant/vendor/edamov/pushok/src/Client.php on line 124 and defined in /vagrant/vendor/edamov/pushok/src/Response.php:144
Stack trace:
#0 /vagrant/vendor/edamov/pushok/src/Client.php(124): Pushok\Response->__construct(0, '', NULL, 'yyyyyy...')
...
#6 {main}
thrown in /vagrant/vendor/edamov/pushok/src/Response.php on line 144

The following line (Client.php:117:) returns null:
$result = curl_multi_getcontent($handle);

@tradingstratagem
Copy link

Ok the problem is related to this #7

@angvp
Copy link
Contributor

angvp commented Sep 26, 2019

This should be closed also now that #7 is fixed.

@edamov edamov closed this as completed Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants