Alexander m's patch to fix caching of require()

This is an in-progress PR for the issue of require() caching files.

The current fix has a problem when using require() on a symlink php file: the __DIR__ variable is set to the directory of the symlink, not the directory of the actual file, which contradicts php's behaviour.