Welcome Guest, Not a member yet? Register   Sign In
How to keep a php socket open
#1

Hi all,

I'm using CodeIgniter as a front end for a home control system.

One of the devices I want to control has a socket interface.  To talk to it I have to open the socket and keep it open while I perhaps send/receive multiple packets based on links on the control webpage.

I have never tried to do this in php in general and I seem to think that based on my prior experience this is not something I can do as the instance is pretty much created on each request if I am right.

I may not be explaining this well but here is the basic idea:

127.0.0.1/index.php/control

This would display a control web page with various links.  One of the links would be something like initiate communication with power device.  So this might be something like:

127.0.0.1/index.php/control/initiatepowercomm

In the initiatepowercomm method in the control controller I would need to open a socket in php.  I need this socket to remain open so I can't destroy the instance of the socket.  Later commands need that socket to be open.  The problem is the power device "wakes up" when the socket is opened and accepts commands.  It "goes to sleep" when the socket closes.  So I cannot be opening and closing the socket on each request.  For example after doing the line above to initiate comm I might want to do something like:

127.0.0.1/index.php/control/setuppowercommparms

This would need to use the prior opened socket and send a bunch of stuff to the power controller.  Basically I need something to hold the socket open until I at some point terminate the connection.

Am I correct that doing this directly in php with CodeIgniter is not going to work?  IE it seems that when say the controller code initiatepowercomm finishes that the php socket I opened will likely die since the instance of php dies.  Is that correct?

If I am correct then I guess my only other way to do this is a small daemon program that I can make calls to from php that can manage the socket and keep it open.

I am open to other ideas.

Thanks in advance!
Reply


Messages In This Thread
How to keep a php socket open - by MarkWS7M - 06-15-2017, 01:04 PM
RE: How to keep a php socket open - by skunkbad - 06-15-2017, 02:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB