I’m trying to build a PHP application that can grab recent messages from a Twitch stream’s chat. I’ve been looking at the official Twitch API documentation but it doesn’t seem like they offer direct chat message endpoints. Has anyone figured out a workaround for this? I need to pull the most recent chat activity from a specific channel and process it in my PHP backend. What would be the best approach to accomplish this? Are there any alternative methods or unofficial APIs that might work for retrieving live chat data from Twitch streams?
honestly, just use a third-party service like tmi.js on a sep process and dump chat logs to mysql or redis. your php app can query that data without dealing with websocket headaches. ive tried the irc route - it breaks constantly when twitch changes stuff.
You’re right - Twitch doesn’t offer REST endpoints for chat. Instead, you’ll need to connect to their IRC servers. I have successfully done this using ReactPHP’s socket client, by connecting to irc.chat.twitch.tv on port 6667. Authentication is carried out with OAuth, and then you can join the channel you wish to monitor. Be aware that parsing IRC messages to extract the actual chat content can be a bit tedious. WebSockets are another option with Twitch’s newer chat system, but they require careful connection management. Regardless of the method, ensure your PHP script runs continuously, rather than making one-off HTTP requests; using Supervisor can help keep it running effectively. In my experience, IRC tends to be more reliable and better documented.
I’ve dealt with this before and skipped IRC entirely. Used Twitch EventSub API with webhooks instead - worked great. You subscribe to chat message events and Twitch sends them straight to your PHP endpoint. Need ngrok or a public server for testing, but it’s way more reliable than keeping connections alive. Also tried the Twitch CLI tool to grab chat data and process it with PHP scripts, but that adds extra complexity. If you need real-time processing, run a Node.js service next to your PHP app. Have Node handle the WebSocket connections and feed data to PHP through a local API or database. This hybrid setup works well in production when PHP’s threading limits cause issues with persistent connections.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.