Every so often, things work in my local PHP development environment, while in my test environment on my server, things do not. It's a nightmare t开发者_JS百科o debug this. If I had a console like Rails provides, debugging would be much much simpler.
Is there anything like the Rails console but for PHP?
I should mention that I am using a home-brewn PHP application.
PHP has a basic interactive shell available by running php -a
. It doesn't have the bells and whistles of a framework-based console though.
More info can be found in the docs: http://docs.php.net/commandline.interactive
Like webbiedave mentioned php is a language and Rails is a framework of Ruby. However, you could insert "break-points" into your php Script - and either execute from the browser - or if you have php-cli installed execute the script from CLI (Which isn't exactly the same as the browser, but may also provide more helpful information).
A few other tips - dump the environment settings for each machine, devel and production (with a simple script that has
<?php phpinfo(); ?>
And compare the differences - this may help highlight why certain portions are failing between environments.
Lastly you can run php interactively with php -a much like you can with irb and ruby though it may not be as helpful in this situation.
You can roll your own application console with the -d
and -a
flags for the php-cli. It would be something like:
php -d auto_prepend_file=init.php -a
Your init.php
would be whatever file bootstraps your application code. E.g. for WordPress, this would be wp-load.php.
http://franklinstrube.com/blog/rails-like-console-php/
php -a
is not very useful.
I suggest you write a small script like below and place it in /usr/bin:
import readline
from subprocess import call
pre_lines = """
ini_set("display_errors", 1);
error_reporting(E_ALL);
date_default_timezone_set("GMT");
"""
if __name__ == '__main__':
try:
call(["php", "--version"])
print
while True:
user_input = raw_input('php> ')
if user_input.strip() == "":
continue
elif user_input.find("=")>=0 and user_input.find("==")==-1:
pre_lines += user_input + ";\n"
elif user_input.find(";")>=0:
call(["php", "-r", "%s\n%s" % (pre_lines, user_input)])
else:
call(["php", "-r", "%s\nvar_export(%s);" % (pre_lines, user_input)])
print
except EOFError:
print "Bye"
except KeyboardInterrupt:
print "Bye"
except OSError:
print "You either don't have PHP installed, or the PHP binary is not in PATH"
With above, you'll have readline support and check values of equations easily.
精彩评论