简体   繁体   中英

PHP CLI - Pass website URL for rewrite rules

I am using Laravel on PHP5.5. Inside of /app/routes.php I can define routes for when someone visits ie www.website.com/route . This is then re-written to the index.php file via the .htaccess .

When I go to troubleshoot this via command line, for example:

strace -FTs 1000 php index.php

I am unable to get served my particular route, making it very hard to trouble shoot what is going on. This also translates over to any other system that uses index.php to route requests (eg Wordpress)

So my question is, is there a way for me to run via command line something along the lines of:

php index.php --request-path="/route"

that will work the same way as

http://www.website.com/route

If you just call the index.php file you're not getting the full web server environment (among others, the contents of the $_SERVER and $_REQUEST variables) that frameworks like Laravel rely on to initialize themselves, and that's why it's not working.

You should look into running PHP's local dev server if you don't have apache running for development:

http://php.net/manual/en/features.commandline.webserver.php

And then make your requests over the local web server instead, to ensure that your environment is properly initialized for the framework.

With regards to what seems to be your actual goal here, if you're trying to debug and step through your code, look into PHP's XDebug extension, and use an IDE such as Eclipse (free) or PhpStorm (paid) that supports debug connections so you can set breakpoints and step through your code that way..

For Eclipse: http://wiki.eclipse.org/Debugging_using_XDebug

For PhpStorm: http://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm

XDebug also includes profiling tools and other instrumentation that can dump to a log while your application is running, which you can then bring into Valgrind or other tools as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM