4

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 to 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.

3
  • 1
    The Symfony Frameworks has a nice console interface. It is extremely useful. Commented May 25, 2010 at 20:03
  • PHP is a language. Rails is a framework. Commented May 25, 2010 at 21:04
  • 1
    @webbiedave The Ruby language itself has a console: 'irb'. The Rails console simply builds on top of this. Commented Apr 26, 2013 at 9:09

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

I think this is the closest thing to what I'm looking for.
1

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.

1 Comment

The problem I experienced was actually due to bad data in the test database, so looking at the system configuration won't always help.
1

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/

1 Comment

This worked for me and it was surprisingly good. I could boot up wordpress and make calls to an active record type of data structure I was developing.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.