1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Live Chat with PHP and AJAX

Discussion in 'Programming' started by Web_Dev_Chris, Sep 23, 2019.

  1. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #21
    There IS such a thing as the right tool for the right job. There are languages more suitable for certain tasks than other languages. Chat systems require a heavy amount of requests and transactions from the server. Every time you send and receive a message requests are being made. On a typical PHP and web server set up that most users use this requires an HTTP request through a web server then the web server initiates PHP which will open the file, parse it, and interpret the code line by line then return the output that the web server delivers to the user. With Node.js it can act as it's own web server omitting the old traditional set up and it's code isn't executed line by line. It's asynchronous.. and the code uses a JIT so that plaintext code will be compiled at run time.. Those are the 3 HUGE advantages of node.js over PHP for a chat system. That's why node.js is a way better tool for creating chat applications than PHP. All of those PHP chat scripts that exist are a web servers night mare and using the language out of it's intended use.
     
    NetStar, Mar 22, 2020 IP
  2. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #22
    It's funny people are still arguing about this. Is the OP achieved what he want now? It's over six months already after he asked the question.

    I think he's trying go cheap. That's what I'm trying to do a decade ago and I can do exactly what he is trying to achieve, yes with PHP and javascript. It's just impractical and useless in production. It's created bad user experience and even Java isn't good enough.

    It's 2020 anyone, if you wan't it that bad, try rust and webassembly.
     
    ketting00, Mar 26, 2020 IP
  3. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #23
    No arguing here. Debating sure. These threads are archived and often found by curious visitors searching for the same topic. More of less the continuing conversation is for them and not the original poster.
     
    NetStar, Mar 26, 2020 IP
  4. Harry H

    Harry H Greenhorn

    Messages:
    27
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    23
    #24
    Rust and webassembly??? What? The bottleneck is not on the client side. If you couldn't get it to work properly in java you're doing something wrong. All the benefits listed for node.js above are also applicable to java, except the asynchronous model. You can do things asynchronously but you need libraries. The best user experience is always going to be with websockets, so that you're not pinging the server continuously. Also the whole PHP recompiles the file is out of date now if you can configure the server yourself and it's not a cheap shared host.

    https://hub.packtpub.com/php-8-and-7-4-to-come-with-just-in-time-jit-to-make-most-cpu-intensive-workloads-run-significantly-faster/
    https://www.cloudways.com/blog/integrate-php-opcache/

    I still personally prefer node.js or scala... but this wide gap you're seeing just isn't there anymore.
     
    Harry H, Mar 27, 2020 IP
  5. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #25
    I get it done right. I just don't like it.
    I write a node.js websocket library for myself. I don't even use others' libraries like ws and websocket. I even try use node.js to do live stream, live broadcast, it's just not the right tool though. Node.js (or javascript) cannot handle this. It slows.
    Thanks for suggestion. I've already ditched PHP. I won't use it again.
     
    ketting00, Mar 29, 2020 IP
  6. Harry H

    Harry H Greenhorn

    Messages:
    27
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    23
    #26
    Where does it slow? Where is the bottleneck? You can't just say a language is slow. Erlang is a really slow language compared to others but it's used in telecommunications to run massive networks because the bottleneck is not on the CPU. There's massive companies that are getting great speed out of node.js (paypal), scala/java (twitter), and php (facebook). Facebook have probably done the most work to get over the negative aspects of the language to get the performance up but it can still be an effective tool for most companies. How are you so sure it's the language that is giving you the bottleneck. Node.js V8 compiler is unbelievably fast, the only thing that slows node.js down is the lack of parallelism, although for many low CPU projects it's actually faster to round robin on one core.
     
    Harry H, Mar 29, 2020 IP
  7. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #27
    Why even bring up FaceBook then? It is absolutely not the normal language, set up, interpreter/compiler that most companies would use or could use... What we DO know is that PHP was too slow for facebook and did not meet their needs. SO FaceBook created their version of PHP, internal framework and compiler. There's also a lot more to FaceBook than just PHP. I think this is a POOR comparison to plead the case for PHP.

    PHP7 is a huge improvement over PHP5. It's a LOT faster and promising. With the rumors of a JIT on the horizon for PHP8 it becomes even more promising. If PHP can follow Node's lead with a stable internal server to eliminate that old school apache configuration and runs on a JIT you may now have a case. However, right now PHP sucks for making anything that is going to get high traffic. It is true that you can scale PHP and it can work just fine with high traffic web sites but you will be optimizing for scalability a lot sooner and you will encounter a lot of problems that may not happen in more suitable languages. Now most companies will NEVER get to that point....but when you do it SUCKS with PHP! I love the language and love the work flow...but damn I will not use it for a serious project. I switched to Golang due to PHP being a huge headache!!
     
    NetStar, Mar 29, 2020 IP
    ketting00 likes this.
  8. Harry H

    Harry H Greenhorn

    Messages:
    27
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    23
    #28
    I actually agree with your reply here. PHP is harder to scale, however facebook open sourced a lot of their code to scale it which is why I don't view it as an impossibility. If you have a good reason to use PHP I'd never avoid a great library on the platform just because of it's drawbacks. It's never my first choice though. Java & node.js are fast as heck and none of those points are valid.
     
    Harry H, Mar 30, 2020 IP
  9. Harry H

    Harry H Greenhorn

    Messages:
    27
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    23
    #29
    Just wanted to post a benchmark which shows PHP to actually outperform node.js:
    https://thinkmobiles.com/blog/php-vs-nodejs/
    We all know these simple benchmarks don't mean a whole lot, but... PHP 7 is a massive step up. Such a step up that optimization and scaling is now often not a major reason to move away from PHP imo.
     
    Harry H, Mar 30, 2020 IP
  10. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #30
    That must have been the strangest comparison "test" I have ever read. It never used real world applicable code and the tests were positioned first by taking away Node.js's advantages. Why would you run synchronous when the benefit is async??? A way better REAL WORLD test to compare Apples to Apples would be write code that utilizes a database and template engine of some sort. You'll have a traditional PHP set up with Apache and Node.js as a standalone server (or even run with a reverse proxy using Nginx). I guarantee you that Node.js with a standalone server, already persistent database connection upon startup, and code being compiled and run via the Chrome V8 will ALWAYS outperform a request to Apache, A server opening a PHP file, Parsing the contents and reading/executing line by line via an Interpreter, connecting on the fly to a database, and returning data to a web server that spits it back out to the browser. It's utter non-sense to run a routine of hand selected functions outside of a real world application to get results to plead your case that PHP is faster than Node.js for web development. That's like me taking a Dodge Neon with a full gas tank then saying it's faster than the Ferrari on empty therefor you should race a Dodge Neon. Take the cars to the strip and run on the same track, the same day, and with the same driver. Sorry.. I'm a PHP fanboy but Node.js has it beat in performance.
     
    NetStar, Mar 30, 2020 IP
  11. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #31
    Node.js now supports HTTP/3, it left PHP in the dust.
     
    ketting00, Mar 31, 2020 IP