r/PHPhelp • u/GuybrushThreepywood • Nov 30 '25
Using PHP to read long-lived stream events
I recently I had a requirement to communicate with some hardware that use a REST api. Unfortunately a long-lived HTTP/TCP stream is also involved.
I decided to implement an ElectronJS/Node solution which I deployed on a client's machine. It works fine, but it is not fun, nor easy to maintain or expand. I am thinking about switching to a webserver running PHP.
Of course, the REST api can be easily handled by PHP. But how can I deal with the long lived streams?
Does FrankenPHP help me here? (I have never used it)
Edit - more details:
The device is an access controller - it is the server, and I want to subscribe to it's events.
The stream is a long-lived HTTP connection (called ISAPI Event Notification). Once you authenticate, you get a continuous stream of multipart XML payloads (each representing an event; e.g. card swipe)
The url usually looks like:
GET /ISAPI/Event/notification/alertStream
Authentication is basic or digest.
The response is always a HTTP response with: Content-Type: multipart/mixed; boundary=--myboundary
Every event comes in its own XML block, something like:
<eventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<eventType>accessControl</eventType>
<eventTrigger>doorCardOrCode</eventTrigger>
<serialNo>12345</serialNo>
<eventTime>2025-12-01T10:15:59Z</eventTime>
<doorNo>1</doorNo>
<cardNo>12345678</cardNo>
<status>success</status>
</eventNotificationAlert>
View all comments
Show parent comment
2
u/isoAntti Dec 10 '25
Start with hello world from the commandline. Edit it a bit to make an example http request. the curl library is very good. Expand from that, focusing on being able to test it all the time. When making decisions in the code, use logging to show parameters and what decision was made. Log also curl requests and responses, e.g. to a file or syslog.
About duration and reconnecting, curl will handle most of those automatically if you make http requests. It's possible you end up in situation where the connection is closed and curl wouldn't reconnect. It doesn't need to be taken care of but know it's possible when debugging.
Look into using same curlhandle all the time or most of the time. You might want to use globals here.