Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Fix value of PHP_SELF when router script is in a subdirectory #12

Merged
merged 1 commit into from
Jan 15, 2019
Merged

Fix value of PHP_SELF when router script is in a subdirectory #12

merged 1 commit into from
Jan 15, 2019

Conversation

andybee
Copy link
Contributor

@andybee andybee commented Dec 6, 2018

PHP's built-in web server sets the value of $_SERVER['PHP_SELF'] differently when the router script is in working directory versus a subdirectory of the working directory. This breaks routing functionality in routing libraries such as Slim.

When the script is in the working directory, the value of PHP_SELF is the filename of the script, but when run from a parent directory of the script it changes to being the path requested of the web server.

This commit changes bootstrap behaviour when referring to the Lambda handler. If it refers to a script in a subdirectory of the task root, it changes the chdir call to enter that directory before running the PHP internal web-server, so that it can refer to the script filename as being in the working directory.

This poses no change to how the layer is configured or run, but PHP_SELF now correctly refers to the filename and this solves the issue with Slim.

Resolves: #11

PHP's built-in web server sets the value of `$_SERVER['PHP_SELF']` differently
when the router script is in working directory versus a subdirectory of the
working directory. This breaks routing functionality in routing libraries such
as [Slim](https://www.slimframework.com).

When the script is in the working directory, the value of `PHP_SELF` is the
filename of the script, but when run from a parent directory of the script it
changes to being the path requested of the web server.

This commit changes `bootstrap` behaviour when referring to the Lambda handler.
If it refers to a script in a subdirectory of the task root, it changes the
`chdir` call to enter that directory before running the PHP internal web-server,
so that it can refer to the script filename as being in the working directory.

This poses no change to how the layer is configured or run, but `PHP_SELF` now
correctly refers to the filename and this solves the issue with Slim.

Resolves: #11
@txase
Copy link
Member

txase commented Dec 7, 2018

See discussion in #11 around whether the current behavior is broken due to the layer or due to the PHP webserver, and whether this PR is the correct resolution.

Copy link
Member

@txase txase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be an absolutely clear definition of the behavior of PHP_SELF, but this change appears to fix the behavior of the layer when used with popular routing libraries. The implementation looks correct.

Thanks!

@txase txase merged commit 40472ac into stackery:development Jan 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants