php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75647 `-t dir` changed behavior when combined with a router file
Submitted: 2017-12-07 15:09 UTC Modified: 2017-12-07 15:36 UTC
From: martin dot st at wolke7 dot net Assigned:
Status: Duplicate Package: Built-in web server
PHP Version: 7.1.12 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: martin dot st at wolke7 dot net
New email:
PHP Version: OS:

 

 [2017-12-07 15:09 UTC] martin dot st at wolke7 dot net
Description:
------------
This is my first bug report to PHP, so please don't be mad at me. 

The following command used to work fine but stopped working in PHP 7.1.12
`php -S localhost:8000 -t directory directory/router.php`

It seems like somebody changed the way relative paths are handled when using the `-t` option and a router file at the same time. 

This statement also shows how this was working 3 months ago:
http://php.net/manual/en/features.commandline.webserver.php#121501

I think it might be related to the following commit, but I'm not very sure (I'm not a C developer):
http://git.php.net/?p=php-src.git;a=commit;h=816758eda2bcdd69ba505fb6bbb79124a7bf2254


What actually happens
---------------------

Starting the server works nicely:

$ php -S localhost:8000 -t directory directory/router.php
PHP 7.1.12 Development Server started at Thu Dec  7 15:00:15 2017
Listening on http://localhost:8000
Document root is [/home/myuser/mycode/directory]
Press Ctrl-C to quit.

When a request comes in, I get a message like the following (both in the result and in the server output):
[Thu Dec  7 15:00:21 2017] PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0
[Thu Dec  7 15:00:21 2017] PHP Fatal error:  Unknown: Failed opening required '/home/myuser/mycode/directory/directory/router.php' (include_path='.:/home/rof/.phpenv/versions/7.1.12/lib/php/pear') in Unknown on line 0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-07 15:22 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2017-12-07 15:22 UTC] requinix@php.net
That is indeed the right commit.

However it's more or less an intentional change: the router script is now relative to the document root and not the current directory. An absolute path will work too, of course. See bug #75604.

$ php -S localhost:8000 -t directory router.php
$ php -S localhost:8000 -t directory `pwd`/directory/router.php
 [2017-12-07 15:26 UTC] requinix@php.net
No, not "more or less". It is intentional and the commit clearly shows it as such.
 [2017-12-07 15:36 UTC] nikic@php.net
@requinix: The commit shows that this was an unintended side-effect of another fix. It should be reverted, because it's an unnecessary BC break for a case where the new behavior doesn't even make sense. Paths provided on the CLI should be interpreted relative to the CLI CWD...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC