Been working on PHP for a year now, still not sure how PHP decides what is considered to be the entry point.
If I set my docroot to a ‘projectwww’ directory, what file in that dir gets consumed as the entry? I assumed it was index.php, but I just deleted that file out of my project and I started getting redirected elsewhere.
Advertisement
Answer
PHP doesn’t decide anything. You, as website visitor, are making that decision when you click on a link or type a URL in the browser’s location bar. If the response contains HTML, the resources contained in the document will eventually trigger the rest of requests:
GET https://stackoverflow.com/questions/70624361/how-does-one-determine-the-entry-point-for-a-php-project GET https://fonts.gstatic.com/s/robotoslab/v16/BngbUXZYTXPIvIBgJJSb6s3BzlRRfKOFbvjojISmb2Rm.ttf POST https://stackoverflow.com/posts/validate-body ...
The target server will have an HTTP server program running, or the request will time out without response. Such software (Apache, IIS, Nginx, CloudFront…) needs to be configured so it knows how to handle the request. Some possible options include:
- Redirect the browser to another location
- Submit the request internally to another server and send its response back
- Map to a set of physical files and directories on the server’s disk
- Pass the request to a handler program (executable found on server’s disk or process listening on internal port)
It’s usually a combination of several features.
The PHP interpreter can be running as web server module, be invoked from disk or be running all the time as network process. Eventually, the PHP interpreter receives a request (not all requests to server are typically meant to be processed as PHP) with this information:
- What PHP code or script to execute.
- Original URL requested.
- Request HTTP headers.
- Environment variables.
PHP handles the request, executes the appropriate PHP code and emits its response.