Consider the notification system in Google calendar. It sends you a push/email notification user specified time (like 10 minutes/10 hours etc). How is this implemented on the server side? Assuming Google calendar is on a PHP/Apache platform, is there a script which runs continuously and checks the current time against the time in database and then push notifications when the times match? Basic question - how does the server know when to push the notifications?
Is it easier to do this on Apache/PHP or Node.js?
You are asking about black magic. Are you sure you want to know the answer?
In answer your hypothetical question, "If Google uses PHP for scheduled notifications how do they do it?" the best answer would be cron. It really has nothing to do with PHP, it is a service run by the operating system (at least on *nix-based systems) which wakes up every minute, checks a to-do list, runs things it needs to run, and then goes back to sleep. The "minute" thing is a very important detail: it doesn't run constantly, it doesn't run tasks with a by-the-second precision, only every minute.
Cron can run any executable script, and is designed to run with the permissions of the person who scheduled the cron task, so it can run shell scripts out of your home directory and it can run php scripts if they are correctly configured.
As an alternative to cron, one could also write a new service that continually runs as a daemon, which wakes up every so often to check if notifications need to be sent. You would lose the standardized behavior of cron, but you could do by-the-second scheduling, and anything else your heart desires.
As for knowing when to send notifications, you create a database containing a list of tasks and when they should run, and then find a nicely optimized query to grab the current set and process them. Cron, or your custom service (which you have written in Node.js because all the cool kids are using Node.js), runs this query every minute / every so many seconds. And if you are Google, you then figure out how to scale this out to a thousand machines.
First of all, PHP and Node.js are two different laugnages. For the purpose of scheduler, different solutions are implemented accordingly.
Because the nature of PHP, from its name, PHP is a HyperText Processor. Everytime a visitor access an URL on your website, this processor will run once to process the request, then stop. There is no system-wide control for PHP, which means it don't have the ability to schedule a long term task by itself. So PHP developers has developed two methods to trigger the scheduler. Here I take the Wordpress(WP) for example:
In short, a script tiggered by remote user, not relaible
In short, a script tiggered by server system according to the accurate schedule, very relaible
For Node.js, it is a different story. By design, Node.js runs on a single process, this process will keep running until it was terminated by system administrator. This process will also handling all the requests from all the clients globally. Unlike the PHP which only process the PHP file, Node.js is a complete application container that has the abliity to do more things than PHP. There are scheduler modules already implemented for Node.js. Check node-schedule for more detail.