I have a php script the I often run using CLI (regular ssh terminal).
<?php
class foo {
public function __construct() {
echo("Hello world");
}
}
// script starts here...
$bar = new foo();
?>
When I run the code using php filename.php I get the Hello world stagnant as expected. Problem is that when i include the file from other php file I get the same thing (which I don’t want).
How can I prevent code from running when file include but still use it as a CLI script?
You can test if
$argv[0] == __FILE__to see if the file called form the command line is the same as the included file.