Skip to content
Advertisement

Bootstrap PHP file before `php -a`

Is there a way to run a bootstrap code at every start of PHP interactive shell? Something like this:

php --bootstrap "autoload.php" -a

Advertisement

Answer

You can use the auto_append_file directive for your cli configuration.

Example mine:

auto_prepend_file = /mnt/d/temp/boot.php

boot.php file:

<?php
$code = "aabbcc";

php -a test:

ariefbayu@DESKTOP-E76L6HH:/mnt/d/temp$ php -a
Interactive mode enabled

php > echo $code;
aabbcc
php >
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement