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.