How does PHP run time work?

Asked

Viewed 350 times

4

I’ve always been interested in how long my code runs. The problem is that I don’t quite understand how the execution of PHP code works. Below are the questions:

On the server, the PHP code is executed at each request or it is always working?

If it is always running, it creates a new execution for each new visitor?

If it is not always running, is there any way to keep it running? (even after the customer has left the site)

On the Internet I only found tutorials about the syntax of the language and how to increase the running time (which makes no sense if I don’t know how it works).

  • Just to complement, PHP is not a server, the server is apache, Nginx, iis, etc. The server that "creates a new execution instance". As for running time, it is the time limit that php can be "open".

2 answers

3


On the server, php code is executed at each request or it is always working?

Yes, as with any technology, there is no way anything can work without being executed every time that activity is desired.

If it is always running, it creates a new execution for each new visitor?

Who? Your code in PHP? No, it only runs when it is needed, nor would it be running without knowing what to do. It creates a new instance of execution each comes that is called, but there are optimizations for it.

If it is not always running, is there any way to keep it running? (even after the customer has left the site)

In PHP for web there is essentially no way. It is even possible, but it is wrong and will bring problems, nor does it make sense to do this in PHP for web. If you need it, you’d better choose another technology.

  • thanks for the help, you said it was possible to do... could you say how? and you could quote that other technology would serve for this need?

  • But because you want to run the code all the time?

  • @Mizukearo for you to make a php code run from time to time without someone creating an instance, would be using linux crontab http://e-tinet.com/linux/agendar-script-php-crontab-no-linux/

  • @Mizukearo As is already something ample to ask. Essentially any technology other than PHP.This language is good for making simple websites, anything that goes beyond that it is not suitable. People are using where it doesn’t fit and are producing aberrations of applications.

  • @twsouza the goal is to create my own "index" of some web pages making php create requests for them, kind of a personal search engine... but apparently this is not the right language for it...

  • @Mizukearo is really not a good language, I recommend it, by own opinion, or Golang or Node.js.

Show 1 more comment

0

If I understand your doubt well, PHP runs every request, when it is 'called' it creates a session that would be an open page in the browser, this session is active until the browser remains open ( or vc can define how long the session is open by the php syntax ) to each new visitor you can yes run a new session (again by the php syntax ) but will much of your need... Give a look at this site, help pacas for those who are starting or more intermediate level. http://br.phptherightway.com/#site-header

Browser other questions tagged

You are not signed in. Login or sign up in order to post.