Google FCM or Google Cloud Messaging is terrible to setup, understand and use. Documentation looks solid, but it does not give answers to tons of small questions of how it works behind the scene. How to expire subscription? How to unsubscribe everybody from given topic?

I tried to use FCM for push notifications in Web. I even don’t need UI notifications, just some data to be pushed to clients.

Almost succeeded, but last strike came unexpected. It does not work in incognito mode, by design, wtf!!!

Switched to socket.io and got it working with PHP in half of day.

So:

  • FCM - Almost a week of setup through console, reading, trying examples, googling issues.
  • Socket.IO - 1 day to setup docker with nginx redirect for websockets, docker container for phpsocket.io and code.

Something is very wrong, when product is so hard to use that faster and easier to create own.

# Highlights of my PHP + socket.io configuration

phosocket.io + socket.io client

nginx.conf

    location /socket.io {
        proxy_pass http://sio;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

Dockerfile

FROM php:7.2-cli AS base
RUN apt-get update && docker-php-ext-install pcntl
CMD [ "php", "./socket.php", "start" ]

socket.php

<?php
use Workerman\Worker;
use PHPSocketIO\SocketIO;
require_once __DIR__ . '/vendor/autoload.php';

$io = new SocketIO(80);
$io->on('connection', function ($socket) use ($io) {
    $socket->on('event', function ($msg) use ($io) {
        $io->emit('event', $msg);
    });
});
Worker::runAll();

HTML + Javascript

<script>
var socket = io();
socket.on('connect', function(){
  console.log('connect');
});
socket.on('event', function(){
  console.log('event');
});
</script>