NotionCommotion Posted February 5, 2017 Share Posted February 5, 2017 Is it possible to use PHP to create a unix domain socket to a file path such as /tmp/pa and listen for connections? If so, where should I start? Can a library such as reactphp be used? Thanks Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 5, 2017 Share Posted February 5, 2017 If so, where should I start? With a Google search or the PHP manual (hint: stream functions). Can a library such as reactphp be used? They're working on it. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 5, 2017 Author Share Posted February 5, 2017 Thanks Jacques1, I had done so, and thought that http://php.net/manual/en/function.stream-socket-server.php is the right direction. They give examples of Internet Domain sockets (AF_INET) such as TCP and UDP, but not Unix domain sockets. For unix sockets, I will try using unix:///tmp/pa. Am I on the right path? Any other words of wisdom? Thanks Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 5, 2017 Share Posted February 5, 2017 unix is the scheme for Unix sockets, yes. A fair warning: If you're going back to low-level sockets (for whatever reason), be prepared for extensive research and learning on your own. Understanding the PHP stream API is actually the trivial part. Then you need to implement and possibly even design a protocol to handle the communication, which isn't something you'll find in a step-by-step tutorial. And as always, we can only comment on the information you've provided. Whether your design choices even make sense is impossible to tell without knowing the full context. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 5, 2017 Author Share Posted February 5, 2017 I understand that I provided very little information and can not expect much comments. I am in the discovery phase, and have very little information to give. I am building a PHP client application which bidirectionally communicates to a remote server using ReactPHP. This part is working. Now, it needs to bidirectionally communicate to a C++ application residing on the same machine. Messages from the PHP client app need to somehow be transmitted to the C++ app, and the C++ app needs to somehow transmit messages to the PHP app. The C++ author recommends using Unix domain sockets along with JSON-RPC where the C++ app is a client and the PHP app is a server. I do not have enough knowledge or expertise on this subject to question doing differently. What information would be needed to agree with this recommend or recommend doing differently? Thanks Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 5, 2017 Share Posted February 5, 2017 If the C++ application already has an implementation for JSON-RPC over Unix domain sockets, you don't really have a choice. If both applications currently have no communication component at all, I would use a message-oriented mechanism (e. g. a message queue), so that you don't have to assemble the data from a byte stream. Quote Link to comment Share on other sites More sharing options...
benanamen Posted February 5, 2017 Share Posted February 5, 2017 As I mentioned in a previous PM, I really think Node.js is a much better tool for what you're doing. (For as much I understand your project). PM me enough working details of what you're doing and I will see what I can do in Node. I know you are not at a place to learn a new "language" right now. It will give me a real example that will help my skills in Node and I will also be able to bumpstart you with learning Node if/when you ever get there. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 5, 2017 Share Posted February 5, 2017 I really think Node.js is a much better tool for what you're doing. Why? Quote Link to comment Share on other sites More sharing options...
benanamen Posted February 5, 2017 Share Posted February 5, 2017 From what I have learned of it so far, it seems well suited for real time two way connections using web sockets, which from what I gather from @NotionCommotion's posts and PM's is what he is doing. A node description I read that seems to fit. The main idea of Node.js: use non-blocking, event-driven I/O to remain lightweight and efficient in the face of data-intensive real-time applications that run across distributed devices. Of course, I am just starting to learn it which is why a real project would be nice to work with. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 5, 2017 Author Share Posted February 5, 2017 ... I would use a message-oriented mechanism (e. g. a message queue)... such as redis? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 5, 2017 Share Posted February 5, 2017 Redis requires an extra server. I meant something like ZeroMQ. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.