Yes, you can use WebSocket in Heroku. PHP is a very complex language in general when it comes to WebSockets, and I would recommend something else. But no matter what I think, you can do as you please. If you use Heroku, you must follow the standard downtime rules. If the program is inactive for 55 seconds, the program will end. A way to handle this would be to send a ping message from the server every 30 seconds.
https://devcenter.heroku.com/articles/websockets
source share