PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Define leak memory, I'm not sure of the interal workings of apache but its probably apache holding hte document buffer in memory, PHP is executed as an extension of apache so anything PHP or the server itself puts in memory is going to show up owned by httpd, assuming that file never gets unlinked your loop is infinite so I'd assume that'd be quite one large buffer
Yeah the httpd process (apache) is gaining memory over time. Is there any way to flush out this memory in each loop through the PhP? Maybe some kind of PhP.ini setting or something?
theres implicit output buffer flushing, but the issue is that a flush is just changing the owner of that buffer from PHP to apache, the buffer is still sitting in the memory in the same spot so to speak, what I would do is spawn a background process since this seems like a batch task, then set up a queue database to keep track of tasks and when they finish, then you could have an ajax frontend or something of the like or simply just send the user an email when the task finishes, to a URL where they can view the outputs ( output would be saved for later user viewing ).
The web is only meant to do so much directly, sometimes you'll have to write "offline" code so to speak. Perhaps the problem is your data belongs on the disk and not in memory
Nope I must have an endless server push to achieve what I want. Basically I have a camera generating an image on the server which I want to push out to the connected client.
I already have a polling version working, but I need to achieve a push version as well.
HTTP is a stateless protocol. To implement a simulated persistent ( or asynchronous ) interaction you should use ajax, make one call at a time and then append the results to the end of the document
You could very easily replace an image on the page with the image that a script returns, call that script on a timer and achieve the effect you described, all without needless threads hanging on the server and the overhead of holding previous image data in memory
I think we are missing the design concept of server push here. There is no request being made by the client except for the initial request only. The server spawns this PhP thread to endlessly stream image updates via content type multipart/x-mixed-replace telling the application to replace its content very quickly.
There is no browser here, no AJAX, nothing but one simple HTTP request coming from the client side. The server then handles the stream from this point forward.
Well I understand the concept just fine, I'm just saying its not what http is made for. There are other protocools / design approaches to what you're trying to do. Anyways. You dont have output buffering enabled in php.ini by any chance do you? Try disabling that, and play around with those memory functions... I think theres some information thats being overlooked here, what you're trying to do should be possible without using up all that memory from a technical standpoint
I know I am kind of forced into this design by someone's bad code. Originally I wanted to use the AJAX approach and it was beautifully working until this point.
Turn off output buffering eh? I'll try it, at this point I am suffering an apache module written in C++ to attempt the same thing. Thanks for your time though, I really appreciate the insight, anyone accomplish an endless server push with PhP?
No go with ob_end_flush(), the file always exists. Apache seems to be allocating 8K every now and then, for what reason I don't know. Is there a better way to achieve an image push?
well you need to isolate which code is allocating the memory, (using the memory debugging functions I told you about )
For instance if you stop reading files and stop sending output does it keep using memory? And if the file always exists why bother checking if $handle == false
If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
Basically theres too many different things that could be causing it to know for sure without using those memory functions.