Looking for conceptual help...

I am writing a program in C++ to handle socket connections, eventually to be a websocket server. However, the rest of my stack uses PHP for serving up page.

Is there a way to use PHP as an intermediary between the client (JS) and the application (so I don't have to keep track of session data or state in the database to retrieve with each incoming socket request)?

I understand I can't pass the resource (a socket) to the application from PHP, but could I do a 302 with the request from the client? Could I just pass along the request/upgrade request to the application layer in some way?



1 Week
Discussion Span
Last Post by Kyle Wiering

Hello ryantroop,

Based on what you described I can't see why you need PHP as intermediary. In the websocket handshake you have all the cookies and it is easy with C++ to have that session (all the issues with race conditions are the same also) , also I can't see why you need PHP for database handling.

We also use C++ alongside with PHP for websockets (in fact I am preparing for quite some time now , an open application server that takes that logic and expand it in all the life cycle of a PHP application) , we do that because all our web development is in PHP and we didn't want to switch. We use PHP-CPP (Click Here) and load it to PHP as an extension (through fastcgi , to eliminate the need to load it in each request , but there are also other implementations to achieve that).

Writing extensions for PHP in C++ is rather easy and I would dare to say a bit fun ;)

Edited by jkon


This sounds like an interesting problem. It sounds like you know how to do everything else on PHP, except the sockets.

I tend to think about these different then most legacy PHP applications. I like https://reactphp.org/socket/

I like to have my PHP and use it too...

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.