0

I have never dwelled in to node.js however I have now had to, to be able to implement push notifications in my iPhone app.

I have successfully created a node script that successfully pushes apple notifications to mobile devices.

I can run the script via ssh, and it works fine.

I created a php script with the following code...

<?php
    $output = shell_exec("/home1/devjustin/nodejs/bin/node /home1/devjustin/apns/index.js 2>&1");
    print_r ($output);
?>

Now here is my problem...

If I run that php script via my browser, I do not get a notification pop up on my phone. The php script does infact interact with the node script, but it seems to fail towards the very end of the node script, without any explanation at all, without any errors being displayed.

If I run the php script in ssh via, php mobile-push.php, it works as I had hoped it would, and I get a notification pop up on my phone.

So, after days, and I mean literally days, I have not been able to find a solution.

I was wondering if perhaps it was my host. I am currently running a shared server through hostgator, although it seems like all the permissions I required, are there and active.

Any help would be super appreciated. If you want me to provide examples, I am happy to.

I need this feature in my app, so that when an action is performed, and uploaded to my server, I can trigger push notifications to users who the uploaded data affects.

P.S: I created some console.log lines in my node script, and they all show up when running the php script through my browser, except for the console prints surrounding the following segment of my node script:

// index.js
// Actually send the notification
apnProvider.send(notification, deviceToken).then(function(result) {  
    console.log(result);
});

Regards,

Justin.

regards to below discussion with edwin:

console - starting
console - tokens set...
console - second last stage
console for apnProvider - EventEmitter {
  client: 
   Client {
     config: 
      { token: [Object],
        ca: null,
        passphrase: null,
        production: false,
        address: 'api.development.push.apple.com',
        port: 443,
        rejectUnauthorized: true,
        connectionRetryLimit: 10,
        heartBeat: 60000 },
     endpointManager: 
      EventEmitter {
        domain: null,
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _endpoints: [],
        _endpointIndex: 0,
        _config: [Object],
        _connectionFailures: 0 },
     queue: [] },
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined }

//notification console output
{ encoding: 'utf8',
  payload: { id: 123 },
  compiled: false,
  aps: 
   { badge: 3,
     sound: 'ping.aiff',
     alert: 
      { body: '[Cancelled] Friday, 4th of August at 3:00PM.',
        title: 'Business Name' } },
  expiry: 1501839082,
  priority: 10,
  topic: 'com.mybundleid.mybundleid' }

I have ran an strace on the script through php, and this is the break point. Could someone please help me understand this?

console - tokens set...
console - second last stage
open("/proc/meminfo", O_RDONLY|O_CLOEXEC) = 10 --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=26871, si_uid=638} --- +++ killed by SIGABRT +++
  • 1
    are you running php in safe mode? maybe check this answer from the manual of `shell_exec`: http://php.net/manual/en/function.shell-exec.php#118495 – Edwin Aug 04 '17 at 08:05
  • Thanks for asking @Edwin, I did a check, and safe mode is 100% off. – Justin Coates Aug 04 '17 at 08:07
  • 1
    so from your edit, seems that the `shell_exec` part is working, only that you have a problem in js..right? – Edwin Aug 04 '17 at 08:10
  • I followed the output from the link you just provided, and it is printing the same result as it was before. It won't print my last console line. My .js script is working if I call it via ssh, but via php it doesn't seem to fully execute. Also, again, if I call the .php script via ssh, the .js executes fully and properly. – Justin Coates Aug 04 '17 at 08:11
  • 1
    maybe console.log all the variables that you need there like: apnProvider, notification, deviceToken to see if they get init right, before calling send – Edwin Aug 04 '17 at 08:13
  • That's a good idea, I will post the results here. Thank you. – Justin Coates Aug 04 '17 at 08:15
  • I have just updated my question, added the output that my console is providing. Everything seems to be good, but as I mentioned, I am new to node.js. – Justin Coates Aug 04 '17 at 08:21
  • 1
    I don't see the output in your question :) – Edwin Aug 04 '17 at 08:22
  • Added, just had to reformat the way it was presenting. – Justin Coates Aug 04 '17 at 08:24
  • 1
    and how does the notification looks like? – Edwin Aug 04 '17 at 08:27
  • I just updated the question to include the notifications output. It also seems pretty clean on what it is doing, if I am not mistaken :'( – Justin Coates Aug 04 '17 at 08:34
  • 1
    can it be a ssl problem (just google it or search on Stackoverflow)? since you are using port 443. And also maybe try to catch the promise (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch), maybe you get some error – Edwin Aug 04 '17 at 08:38
  • I wouldn't know how to check that, do you? I am trying to access the php script with my https:// but it just returns the same result even though my server is certified as secure. As for the promise, what do you mean? – Justin Coates Aug 04 '17 at 08:39
  • It's not catching a thing, and doesn't seem to be related to the SSL either. I have been banging my head over this for a while. – Justin Coates Aug 04 '17 at 09:01
  • So I ran an strace on the call, and I am getting a break point. Do you have any ideas? – Justin Coates Aug 04 '17 at 09:56
  • this can be related to https://stackoverflow.com/a/8072273/1595977, I can only assume that your object is not correctly translated php -> json -> objectiveC try with a simple object and then check again the structure. Other ideas I don't have right now. – Edwin Aug 04 '17 at 10:31

1 Answers1

0

This error was in relation to the permissions that were being granted to the web user. The only way I would have been able to completely execute the remainder of the code in my file would have been to grant root access, or above web user level privileges.

Since that was not an option I was ready to use, I have instead scrapped the node script, and rewritten the entire push sending notification system in php, using these three links that I found here on SO as my resources (incase anyone else needs assistance with the server side sending).

Sending multiple iphone push notifications + APNS + PHP + Tutorial

Generate .pem file Used to setup Apple PUSH Notification

APNS PHP JSON Payload structure

I can now send push notifications automatically through my app by accessing a php script. This way, with some additional php, users will now be able to interact with each other through apples push notifications whilst in app, or on the web platform.

Regards,

Justin.