To me, the best way is using a background, long-running task (like a daemon), if you have access to a shell in the server. You can communicate with the task by using some kind of command queue, for example through a in memory table on the database.
If you have everything already written in PHP (or want to use a single language), you can just use php-cli.