0

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?

Thanks!

Ryan

3
Contributors
3
Replies
26
Views
3 Months
Discussion Span
Last Post by ryantroop
1

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

0

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...

0

I did look into the idea of writing a php extension, but it seems it's fairly difficult to do so on a windows system. Right now, I have done a reverse proxy through IIS, however it still has some issues...

I don't think I want to use PHP has a socket controller, as there is a lot of overhead with PHP and I am looking at doing something that requires high performance. If I am forced to work in PHP, then I will.. if I can find a way to do with through the reverse proxy, then Ill share my results and process when I figure it all out.

Thanks for the link, though!

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