I\'m working on an online PHP application that has a need for delayed PHP event. Basically I need to be able to execute arbitrary PHP code x many seconds (but it could be da
Here's the correct answer, but you may not like it.
PHP is designed entirely around being used as a request-response (http) language, and thus doesn't support what you are looking for - it's great to hack and find ways around, but it will be just that, a hack, whatever 'solution' you end up getting.
What you really need is an event driven language that supports xmpp, and for that you need look no further than node.js /v8 and the supporting XMPP libraries - this natively supports and is designed for just what you need. you could also go down the Java route, but if you want to port quickly and get a whole host of new features and support for what you are doing, node is the one.
If you insist on going with PHP (as I have many times over many years) the 'lightest' and most effective way to do this is a persistent PHP deamon with an event Queue in a database - sadly!