-
-
Notifications
You must be signed in to change notification settings - Fork 117
Added support for index.php in subdirectories #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Added support for index.php in subdirectories #259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code might be necessary (but I'm not sure) but is not enough to fix the linked issue because the HTTP handler (https://github.com/symfony-cli/symfony-cli/blob/75f91e31404e/local/http/http.go#L201) will not forward the call to PHP at all.
You first need to make sure the handler detects such PHP scripts and then forward the request to PHP
Hey. Thanks for quick review. Just to make sure we are talking about this same. This script is now returning the correct values: mkdir -p web/subdirectory
echo "<?php echo 'root'; " > web/index.php
echo "<?php echo 'subdirectory'; " > web/subdirectory/index.php
go run main.go server:start -d
curl localhost:8000 # returns root
curl localhost:8000/subdirectory # returns subdirectory I think the issue you might be talking about though is that command will refuse to enable PHP if the root PHP file is not available. Is that it? |
Actually, i think we are talking about different things. Currently the behaviour of a server is that it will ignore PHP all together if there's no root index.php, so i didn't change anything there. Going back to your issue. I am crap at GO so forgive me if I say something stupid, but seems that Handler is used for static files and then as a fallback it calls s.callback. The original part of the routing for other .php files is included in envs file, so i guess this one should be too. |
Hum, sorry I was wrong: I misread the Handler part. Everything is fine there. |
Great. Thanks for reviewing. I am happy for that to go. It would be good to know it works on windows too, but it shouldn't have any adverse effects if it doesn't, the feature just wouldn't be available. |
c777a4c
to
7b158c8
Compare
Few fixes
|
6fb1bcf
to
93cb65a
Compare
c8aa21f
to
2a2401d
Compare
Thanks for the fix, I think you removed the empty lines too, so I just squashed it and it's ready to go. Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two last minor comments.
Tomorrow I will play a bit with this to check the performance to be sure this patch does not brings a big hit
2a2401d
to
b86b610
Compare
Added fixes requested. |
Had a quick look with ab: mkdir -p web
echo "<?php echo 'root'; " > web/index.php
go run main.go server:start -d
ab -n 7000 -c 20 http://localhost:8000/foo/foo/foo/foo/foo/foo/foo/foo/foo/foo/foo/foo/foo/foo Both benchmarks had pretty much similar footprint, even that this is pretty hardcore case. Examples:BeforePercentage of the requests served within a certain time (ms) AfterPercentage of the requests served within a certain time (ms) I run it a bunch of times, and the results were not really showing any major differences. Over 7k requests in both branches had problems, but I guess it would be probably logging overflowing or some mac process kicking in. Obviously, it's not really a reliable test, but better than nothing. macbook pro |
b86b610
to
18fc8ce
Compare
OK. I sent over a solution that addresses both of the issues as well as a previous issue with PHP files outside of the document root being executed. I left comments in the code, but I think that's one of the rare situations they might actually be useful going forward. Pretty important thing:
Gonna fix the commits once reviews goes through, as merging them for now is actually causing problems. EDIT: Docs for fastcgi and document_uri in nginx: https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/ $document_uri is same as $uri and $uri is "normalised": "The matching is performed against a normalized URI, after decoding the text encoded in the “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash." |
Hey sorry for the delay. Going to review the code now |
code looks quite complicated indeed :/ what I drafted last week was something similar to this:
EDIT: cleaner version The idea is to explore the path bits by bits (parts separated by Regarding the ".." we don't really care if they allow relative navigation in the path, this will not end up with a path one could have send directly. The same is probably we true for repeated slashes. |
I mean, if we don't care about the path support for ".." and "//" then we can just do a quick break. if( pathInfo != path.Clean(pathInfo) ){
return p.passthru, pathInfo
} And that will clean a lot of code. Said that, not sure if we shouldn't support it, so people can test their frameworks with it to actually make sure it's resolved. When it comes to the loop, I think having a split might be a bit easier for people to figure it out and when we actually add all the edge cases ( sub/index.php/ vs sub/index.php, // and ../ support ) I think it will end up with the similar amount of code. Current code currently also starts from the back and moves to the start, just does that from the array. I can probably try to optimise a few things, but it would be a line or two tops if we want to keep all the features and I am not sure if it will actually simplify code. |
I'm not saying we should clean the pathinfo and not support having
That's the reason why the code becomes complicated: there are a lot of conditions to deal with edge cases |
OK. I had time to set up a basic wp nginx example and actually learned that all the paths will be cleaned up by default, which is completely against what I got from docs :) I am not sure how it is with other servers, but I found some mentions of path normalisation in apache too. I guess that would mean, that if we want to make the server similar to that of two main ones we should probably always normalise path. That will remove a lot of if statements, but at this same time, it will make it not back-compatible for those not sanitised URLs currently supported. I am not really sure if that's a problem as I can see a small chance someone on purpose used I am gonna send an update to the code tomorrow with normalising path for all requests. |
#237
It's my first go PR and I wasn't able to find any contributor rules or anything like that, so it's straightforward PR. I know I am going to have to change a few things, so don't worry about bashing it :)