Page 1 of 1

Question on browser php file loading mechanics

Posted: Wed Nov 26, 2014 12:53 pm
by PHPHelpNeeded
Hi,

For instance, when exploring the Socket Server and Socket Client examples I found a php.net manual, I was puzzled about how the browser behaves when there is an infinite loop (or while) running.

When the infinite loop or do while is active, the Client socket page doesn't fully load on the browser, and that's because it process has not finished completing, and since browsers read web files from top to bottom, if it is stuck in the middle, then the page does not load at all.

But I found a way to keep it simple, now I have come up with a way to let the Server socket remain running (of course, that's why it is called a server). But I noticed that when I was trying to implement the concept of sending a packet of information (or as I would name it, a token), I don't require to keep the client socket running in a loop (sort of speak, to keep the connection going) because all I need is for the client to send information and the server responding accordingly. How it responds of course is according to what the token contains. So while using the Server socket which accepts the multiple client connections, I was getting "socket_read() failed..." messages everytime the a client page that I had start would close, or when I would send the "quit" command to close the connection between the server and client...the reason I was getting the socket_read() fail error is because of just that, I rewrote or twitched it a little to suite my needs, so that when the client sends its token, it would also close the socket connection so that the page would not stay on the loading instance. So that was not working well because at the other end, the server side, I was using Multi-socket connection algorithm.

To avoid all that hassle, I went instead with the single Server Socket connection along with the my version of the Client Socket connection (now it works beautifully). I can say, now I understand PHP sockets, at least for the basic part.

Now my question has to do with Concurrency or multithread or threads. Obviously, PHP does not work like Java, and that's the beauty of Java. But I am not writing Java anymore, so I want to know, is there a way to accomplish concurrency with PHP.

Or upon each instance that there is a change in the content, you do a refresh of the page? but wouldn't you get the flicker? wouldn't you be stuck on the reloading process? How can one make this work?

Thanks.

Re: Question on browser php file loading mechanics

Posted: Wed Nov 26, 2014 5:33 pm
by requinix
Have you looked into WebSockets yet?

Re: Question on browser php file loading mechanics

Posted: Wed Nov 26, 2014 7:06 pm
by PHPHelpNeeded
Good point.

I do have to think about possibility of outsourcing other languages to accomplish what I cannot do with php.

WebSockets relates to JavaScript. I didn't know that, but since you brought it up can you emphasize on what exactly are you referring to.

Are you saying that with WebSockets since it is JavaScript base, you don't have the same issues I find myself in with PHP sockets?

Re: Question on browser php file loading mechanics

Posted: Wed Nov 26, 2014 7:33 pm
by requinix
WebSockets is basically the entire communication protocol and probably the best way of dealing with sockets in general in browsers. AFAIK it has all the procedural stuff already detailed, and there are implementations (eg, Ratchet, PHP-Websockets) already so you don't have to do any of that socket work by yourself.

Re: Question on browser php file loading mechanics

Posted: Wed Nov 26, 2014 7:42 pm
by PHPHelpNeeded
requinix wrote:WebSockets is basically the entire communication protocol and probably the best way of dealing with sockets in general in browsers. AFAIK it has all the procedural stuff already detailed, and there are implementations (eg, Ratchet, PHP-Websockets) already so you don't have to do any of that socket work by yourself.
Thank you.

UPDATE: right about when the instructions to install Rachet came to this: "Composer is an application written in PHP that will manage external PHP libraries within your project. Ratchet requires React, Guzzle, and Symfony2's HttpFoundation in order to work. It would be a pain in the butt to have to download Ratchet, then download those three libraries in order to make Ratchet work. Oh, and make sure you download the right versions or else there could be problems. But, you don't have to worry about that, thanks to Composer!"

Where it says it requires React, Guzzle, and Symfony2's HttpFoundation, are those standalone applications? because I tried to find them in Eclipse market place, and I found nothing. I didn't download a Symfony program for eclipse but I don't know if that's the right version for this purpose.

Anyway, I will keep trying.

Re: Question on browser php file loading mechanics

Posted: Wed Nov 26, 2014 8:16 pm
by requinix
React and Guzzle are libraries, Symfony is a framework and Ratchet wants its HttpFoundation component. Ah, the wonders of having all your software requirements spread out around the internet... :x

Download the Composer script. There's just one and it's basically just PHP code. You run that and it can install all those things automatically.

Composer installation, but the process is basically just
1. Download the /installer script
2. Run it through PHP (or you could skip the actual download and do like that page shows to run it directly)
3. That saves a composer.phar. You run that like a regular PHP script and it can install those three things (not to mention other stuff)

If you don't want to deal with Composer and Ratchet, the PHP-Websockets one is just regular PHP code and looks reasonable. And I'm sure there are others.