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
1
u/GuybrushThreepywood Dec 09 '25
Thanks
I initially tried it with Node (+ thankfully TypeScript), and whilst I got it all working, the experience was horrible.
Already the PHP code is far easier to work with.
What you've mentioned about the duration and reconnecting, those are situations that I've not had to deal with yet - but I will soon. I would appreciate any tips and advice you have.