Posted August 10, 2012on:
reason why we need phpsh?
1. it is awesome🙂
2. when we were using ubuntu 10, you can do php -a and it is a decent interactive shell for vanilla php. and i run into problems making phpsh recognizing our own database so i just get by php -a for a while. but now that we upgraded to xfce, it turns out there is licensing issues with read-line, so xfce (and some other distributions) comes with php without read-line support, which means php -a is now practically useless.
3. phpsh can work with your own codebase, which makes testing, prototyping orders of magnitude easier.
so here we go, installing phpsh.
the vanilla one (phpsh) works out quite easy. the trouble is always at (phpsh your_code_base_include_file_list). when you try to access your own php classes, functions etc, it is always class not found. why?
in fact, i don’t understand why. the way phpsh works, it is a python script that invokes a php script, and establishes pipes to the php processes. when you invoke the php script, it calls ‘php file options etc’ directly, which in turn should be reading the /etc/php5/cli/php.ini file, where you can change include_path so it would find your classes.
but it doesn’t work — for some reason, the installation on the network drive doesn’t seem to read in the php.ini on my drive at all. a really local installation in fact can read it.
anyway, how to make it work? lots of options.
1. you can change inside the phpsh.py script, the comm_base parameter, when invoking php, instead of ‘php’, put in ‘php -c /etc/php5/cli/php.ini’ –> this works, i tested. however, not sure if it works with the xdebug enabled version of phpsh.
2. alternatively, you can change the phpsh.php script, do ini_set(‘include_path’, ‘path_to_your_codebase’) and it works, i tested.
the benefits of these approaches are you can put in multiple include paths, in case the php code you want to play with scatters around. but these requires changes every time you update phpsh (if you do that at all).
3. the easiest approach doesn’t require you to do anything — just invoke phpsh include_file_list from the directory you would have put in include_path. –> for most cases, this should just work.
that is a fun few hours to figure out what is going on with phpsh🙂