SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using javascript with php to stream

    I've heard some of you all mentioning using javascript along with PHP for streams to lessen the server load so you don't have to use the flush() function. I made the flush thing finally work in my phpchat, now what is this javascript you speak of?

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either way a lot of requests to the server are made, when using Javascript, you refresh a hidden iframe every X seconds, and grab the contents with javascript, and then write them to the main viewing window.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    phpLive is a very good chat app, you can "push" files and images through the chat. Try downloading the demo and having a look at the code, might point you in some new directions

  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Lange
    Either way a lot of requests to the server are made, when using Javascript, you refresh a hidden iframe every X seconds, and grab the contents with javascript, and then write them to the main viewing window.
    So it wouldn't be all that different from what we have now? Does phpLive use any flash? I don't think PHP can really do server push.

  5. #5
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think it's necessarily a case of PHP not being able to do server push, but rather the software being used to receive it (look here)

    Flash, running as an "application" can receive information from the server in a completely different way than just mere HTML over HTTP...
    My name is Steve, and I'm a super-villian.

  6. #6
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, thanks Lieut data.

    Now back to the original question: Would it greately reduce server load if I used javascript instead of what I'm doing now?

  7. #7
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really, since overall, the server will still need to process nearly as many requests as with your current flush() system. Say 10 users were on your system, chatting back and forth, and your system was designed to refresh the page every 2 seconds, you will be getting 5 page views a second, or about 18,000 views an hour. In addition, the javascript views would require a full HTTP header, while (I think) the flushes would not.
    My name is Steve, and I'm a super-villian.

  8. #8
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, with that method it is slower for the user, and it makes more requests, sends more data, etc.

    The only real difference is there is no continuous open connection, and it requires less javascript.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  9. #9
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So there no way around this unless I use flash heh? Darn.

  10. #10
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now, if this were an IE only environment, you might be able to get off with an Active-X component, but ...

    nah, Flash is probably the only plugin that would work in your case, plus its widely supported...
    My name is Steve, and I'm a super-villian.

  11. #11
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you stream also with a java applet somehow, that of course would require me to learn java but hey, its worth a shot I guess.

  12. #12
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see why not, Java is a full-featured programming language, but I would think that you would have to have a JSP backend, to stream from...

    Thus, PHP is completely thrown out of the equation :-(
    My name is Steve, and I'm a super-villian.

  13. #13
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Darn, my server doesn't support jsp and jsp is even heavier than php on server loads.

  14. #14
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A java applet could access the server in any way it likes no?

    Generally Java-based chat applications are written to interface with an IRC server, because IRC servers were meant for that.

    JSP would have no advantage over PHP, because both of them just work through an HTTP server, no?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  15. #15
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Lange
    A java applet could access the server in any way it likes no?

    Generally Java-based chat applications are written to interface with an IRC server, because IRC servers were meant for that.

    JSP would have no advantage over PHP, because both of them just work through an HTTP server, no?
    Well, the java applet would still need some application running on the server to feed to or receive information from -- usually, as you say, an IRC server. I was of the opinion that JSP technology could run independently of a user generated request, i.e. as an application (an example: here), leaving the front end a java applet or other implementation.

    Then again, I can't say for certain, it's only something I've read about... I could never get into the *swing* of java....
    My name is Steve, and I'm a super-villian.

  16. #16
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, a Java Servlet could do it, I suppose that is JSP...
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  17. #17
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP can do this. I don't want to give away too many secrets, but look into sockets http://us2.php.net/manual/en/ref.sockets.php

    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  18. #18
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    // set_time_limit (0);

    *sees the light*

    Ahh, so a simple PHP script could remain in memory, running as a server...

    Nice, thanks for the tidbit!


    What about a shared hosting environment w/ max_execution_time?
    My name is Steve, and I'm a super-villian.

  19. #19
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, I'm not sure how that would affect things. I run my scripts as a daemon, so they wouldn't be affected by max_execution_time. Might talk to your hosting provider and see what they say....(?)
    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  20. #20
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nah, was just thinking about Archbob -- those functions would be great for my localhost, thanks for sharing (I usually just skipped by them, not really thinking what they could do...)
    My name is Steve, and I'm a super-villian.

  21. #21
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, max_execution_time is a PHP_INI_ALL setting, meaning it can be set within the script, and set_time_limit() sets it.

    (You can only do it if safe mode is off though)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  22. #22
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll certainly have to look into it, if it can decrease server load, that'd be great. Unfortunately two of th main function are php5, CVS only.


    Now time to find out what a socket is because these here arguments are just confusing me.

  23. #23
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Sockets are fantastic and would probably work in your case.

    If you wanted to setup a simple TCP server with PHP and sockets (example in the manual) you could connect to that and it could run on the server, controlling the database and sending info requested by the client (the chat script).

    If you get me

  24. #24
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone give some sort of example on how to work on the client side with this?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  25. #25
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I, like always, am really confused.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •