Group Group Group Group Group Group Group Group Group

I'm getting errors in chapter 7

When I test the php script I get no notifications on the phone, but get these errors in the Vapor project:

[ ERROR ] invalid HTTP method (/starter/.build/checkouts/vapor.git-4756611856651214512/Sources/Vapor/Logging/Logger+LogError.swift:32)
[ DEBUG ] Conform `HTTPParserError` to `Debuggable` for better debug info. (/starter/.build/checkouts/vapor.git-4756611856651214512/Sources/Vapor/Logging/Logger+LogError.swift:34)

I tried various things to find the cause. The php script goes into the tokensToReceiveNotification method, but it doesn’t seem to go into the foreach loop at all, which would mean $tokens is empty. Putting a stop in that method returns this:

Uncaught PDOException!
exception 'PDOException' with message 'could not find driver' in /push_script.php:16
Stack trace:
#0 /push_script.php(16): PDO->__construct('pgsql:host=loca...')
#1 {main}
Stack entered at 0x104b7da70 in /push_script.php on line 0

I’m not sure where to go from here so any help would be appreciated!

I’m so sorry you’re running into an issue! You’re getting the failure in the PHP script because the vapor service is failing, so don’t worry about the PHP issues right now. I know the Vapor team just did another release, I hope there were no breaking changes! I’ll test this tonight when I get home from work.

What stage are you at in the book? The things I could suggest trying:

  1. Make sure you’ve fixed all the IP addresses appropriately.
  2. Try using the final project from the sources to see if maybe there’s an issue with the added code.
  3. Do an “rm -rf .build” at the toplevel of your project to remove all the Vapor stuff and then “vapor xcode -y” again to force it to redownload everything and rebuild. Note this will take a few minutes to complete.
1 Like

Actually, looking at your PHP error…I think you’ve got a PHP which isn’t built with PostgreSQL support. You might need to build a new version of PHP that enables PostgreSQL.

1 Like

@dricard I just ran though chapter 6 and 7 and I was able to successfully send myself a push. I did discover a critical error in one part of the code from chapter 6, so please see this topic:

https://forums.raywenderlich.com/t/missing-line-in-chapter-6s-token-class/51103

Unfortunately that’s not the issue you’re seeing.

1 Like

Actually adding that missing line of code did the trick! I checked and my PHP is current (PHP 7.1.19 (cli) (built: Aug 17 2018 18:03:17)), and I only got the error in the script if I had breakpoints in there.

Anyhow, I just added your line of code (from the linked thread) above and now I’m receiving the push notifications.

Thanks for looking into this for me, I appreciate. I’m learning a lot, this book is a great resource, thanks!

Awesome! I’m glad things are working for you now, and that you’re finding value in the book!

Hi there guys, @dricard @gargoyle i had thw same issue where i was trying to run the php script, i added that line and all worked perfectly !

wil there be a way to send the push directly from the vapor server ? ( via post request)

Thank you

Yes, eventually that will be possible. We are waiting for the Vapor team to finalize how the HTTP/2 stuff will be handled with Apple’s servers. Once that’s available, we’ll make an update for the book.

@gargoyle Awosome cant wait (:wink: