You can use the php.ini setting auto_prepend_file to specify the file that should always be executed before the actual file.
According to the documentation on the interactive shell, this parameter is also active there.
Assuming you don't want to do this initialization every time you start PHP, I would suggest creating a copy of your php.ini (for example, calling it php.ini-interactive) and specifying this configuration file with the -c option: php -c /path/to/php.ini-interactive -a .
(Attached this part after some comments on this answer and the question itself.)
According to a comment (by "Ryan P") on the documentation page for the PHP interactive shell, php -a does not always do the same:
The interactive shell and interactive mode are not the same thing, despite the similar names and functionality.
If you type "php -a" and get the answer "Interactive shell" followed by the prompt "php>", you have an available interactive shell (PHP was compiled with readline support). If instead you get the answer "Interactive mode is on," you do not have an interactive shell available, and this article does not apply to you.
You can also check 'php -m' and see if there is a reading list in output - if not, you don't have an interactive shell.
Interactive mode is essentially similar to running php with stdin as a file. You just enter the code, and when you finish (Ctrl-D), php does whatever you typed, as if it were a regular PHP file (PHTML) so you start interactively with '
I do not have a copy of PHP with an interactive shell available. Apparently I only have interactive mode. I tested (see below) and can confirm that the files configured with auto_prepend_file are executed interactively. However, you may want to review it if you have the same symptoms as me:
tomas@debianvm :~$ cat /tmp/prepend.php <?php echo 'cookies are people too!'; tomas@debianvm :~$ grep auto_prepend_file /etc/php5/cli/php.ini auto_prepend_file = tomas@debianvm :~$ grep auto_prepend_file /etc/php5/cli/php.ini-interactive auto_prepend_file = /tmp/prepend.php tomas@debianvm :~$ php -a Interactive mode enabled tomas@debianvm :~$ php -c /etc/php5/cli/php.ini-interactive -a Interactive mode enabled cookies are people too! Segmentation fault tomas@debianvm :~$ php --version PHP 5.4.4-14+deb7u2 (cli) (built: Jun 5 2013 07:56:44) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
(Keyboard input in this last run of interactive mode is just a return, followed by ctrl-d.)