Rails-like console for PHP
Careful. This may blow your mind.
In PHP, there exists a Rails-like console for almost any application. Simply use the command php -d auto_prepend_file=init.php -a
, where init.php
is the path to the file that loads your application.
For example, in WordPress do:
user@server:/var/www$ php -d auto_prepend_file=wp-load.php -a
Interactive shell
php > $post = get_post(1);
php > print_r($post);
WP_Post Object
(
[ID] => 1
[post_author] => 1
[post_date] => 2013-03-26 03:00:48
[post_date_gmt] => 2013-03-26 03:00:48
[post_content] => Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
[post_title] => Hello world!
[post_excerpt] =>
[post_status] => trash
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => hello-world
[to_ping] =>
[pinged] =>
[post_modified] => 2013-03-26 04:26:03
[post_modified_gmt] => 2013-03-26 04:26:03
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://franklinstrube.local/wordpress/?p=1
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 1
[filter] => raw
)
This can be done for just about any PHP framework, and, in my opinion, is better than rewriting php-cli in Python.
Read more at http://franklinstrube.com/blog/rails-like-console-php/.
Console for WordPress: https://github.com/fstrube/wordpress-console
Console for Magento: https://github.com/fstrube/magento-console
Written by Franklin Strube
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#