cakephp logo

Shhhh! Keep quiet cakephp console

Its been a while since I've had a chance and/or motivation to write any notes down, in the words of Willie Wonka "So much time, so little to do....ahhhh, strike that, reverse it..."

At any rate this note is in relation to the cakePHP console and keeping it quiet. Sometimes you need the verbose / debug information and other times it makes it impossible to work in the same shell window.

Sure from a cron perspective you can direct everything to the void (/dev/null) but other times its not possible. For example when you have an application executable that regularly calls a cakephp shell script to update data to your mysql database. Say you start this application from your shell session and you start doing other work, then blamb you get bombarded with console output. Sure you could have installed the mysql libraries and written the code to directly enter the data but by running it through cakephp's console you can make use if the validation code you have already written.

I found teknoid had an article about keeping your console silent which worked for the most part but still output a couple of linefeeds.

I tracked the offending lines down to other parts of cake 1.2.x libraries but after considering changing those files I decided the best solution for me was to add a -quiet option to the cake console so you could easily switch between testing your code in verbose mode else keep it quiet by simply adding the command line -q script argument.

The cake/console/cake script code was changed as follows :-

Show Plain Text
Bash code
  1. LIB=${0/%cake/}
  2. APP=`pwd`
  3. while getopts ":q" opt; do
  4.   case $opt in
  5.     q)
  6.       quiet=1;
  7.       shift $((OPTIND-1));
  8.       OPTIND=1;
  9.   esac
  10. done
  11. if [ $quiet != 1 ]; then
  12.   clear
  13.   exec php -q ${LIB}cake.php -working "${APP}" "$@"
  14. else
  15.   exec php -q ${LIB}cake.php -working "${APP}" "$@" >/dev/null 2>&1
  16. fi
  17. exit;

You can run the cake script in quiet mode as follows :-

Show Plain Text
Text code
  1. cake -q -app <path> <cake console script>

The code simply consumes the -q argument passed to the cake console script and then runs the script in either the quiet or verbose mode.

Filed under: Cakephp  Tags: Shell

0 Responses to “Shhhh! Keep quiet cakephp console”

Sorry, comments have been closed for this post.
(default) 11 queries took 5 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`221
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`221
6DESCRIBE `categories_posts`220
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'shhhh-keep-quiet-cakephp-console' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (72) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 72 AND `PostsTag`.`tag_id` = `Tag`.`id`) 110
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 72 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 7210