I'm currently struggeling with reading one (and eventually multiple) http event streams.
I have a camera that streams events to me and I'd like to consume those events to trigger some actions.
I'm using the following code for example to open the stream:
$stream = stream_get_contents(fopen('http://IP:port/live/events?param=123¶m2=321', 'r'));
Now, when I just keep reading the stream with an echo, it times out eventually and then nothing hapens further more.
I need to be able to read the HTTP response. So I kinda have a continiously running GET request.
An example of the HTTP request is the following;
GET /live/events HTTP/1.1
Host: 192.168.1.101
Connection: keep-alive
Cookie: sid=60ab2b6b
Then a response would be;
HTTP/1.1 200 OK
Pragma: no-cache
Expires: Thu, 01 Dec 2003 16:00:00 GMT
Connection: close
Content-Type: multipart/mixed; boundary=IPCamEventStreamBoundary
Cache: no-cache
Accept-Ranges: none
--IPCamEventStreamBoundary
Content-Type: image/jpeg
Content-Length: 498749
X-Timestamp: 1620986982002
X-Image-Index: 1
X-Frame-Id: 521699
X-Frame-Timestamp: 757030579
X-Frame-Width: 2560
X-Frame-Height: 1920
binary data
--IPCamEventStreamBoundary
Content-Type: application/json
Content-Length: 308
X-Event-Index: 1
X-Timestamp: 1620986982042
{
"DetectorVersion" : 131072,
"DetectorID" : "{6309907F-5708-47D1-B410-50F02C8882FB}",
"DetectorClassID" : -835316578,
"EventTime" : "13265460582042",
"State" : "dsSignal",
"EventCode" : 100,
"EventInfo" : {},
"EventID" : "{4F34A399-9E02-1846-ADA7-98A2798B46B9}",
"DetectorEventType" : "detSignal"
}
What I need, is to be able to capture that JSON in the body and process it. This should be a continiously running script (using the Laravel framework commands). I have multiple of such stream sources and should be able to get them all at the same time, prefered not having to have a daemon for each camera.
Anyone who has an idea on how to handle this best?