5

I'm a beginner in PHP and making a website that displays basic system information(CPU usage, memory usage etc)of a linux system on a webpage.For the web server, i used the built-in web server:

php -S 192.168.1.36:8000

The frontend uses Bootstrap and JS. The php script i'm using uses Server-Sent Events(learnt about it from here) to send CPU usage, memory usage and disk usage(it gets those from the shell_exec() method) to the front-end approximately once every 2 seconds.

The problem is, the site is very slow to refresh, and occasionally, very slow to load the first time too. When i looked at the JS console, i noticed that the server was streaming data to the webpage even after i pressed the refresh button.Could it be because the connection hasn't been closed??

cgifox
  • 639
  • 11
  • 23
  • 1
    We can not guess what your script does but one thing is for sure: the built-in PHP server is for development and unit testing, not for performance or production. – Julie Pelletier Jul 10 '16 at 06:22
  • install a lamp\wamp stack and you will get much better preformace –  Jul 10 '16 at 06:32
  • @JuliePelletier Yeah, but it takes half a minute to load a small ~100 line webpage! and it performs better when you close the page and reopen it in a new tab. – cgifox Jul 10 '16 at 09:46
  • 1
    The length of the output is completely irrelevant. It is very easy to write a script that takes 1 minute to output a single word: ` – Julie Pelletier Jul 10 '16 at 14:57

1 Answers1

5

The build-in web-server for PHP is for development usage. It is single threaded and when you use it, it just takes the hundredfold of time to initialize an incoming request. And mostly you dont have not only one request but also requests for js, css and images. So it can takes a few seconds to load a full page. It's still not implemented for perfomance.

For a simple test or a short development cycle it is okay to use it, but for intensive development I always prefer and recommend a real webserver.

user2289384
  • 51
  • 1
  • 2