Error 500 - CLI.php - Use of undefined constant STDOUT |
Hi,
i have just installed fresh CI4 using composer (composer create-project codeigniter4/appstarter test) and set baseURL i get this error: Code: Fatal error: Uncaught ErrorException: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php:162 Stack trace: #0 /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php(162): CodeIgniter\Debug\Exceptions->errorHandler(2, 'Use of undefine...', '/var/www/html/t...', 162, Array) #1 /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php(1184): CodeIgniter\CLI\CLI::init() #2 /var/www/html/test/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php(300): include_once('/var/www/html/t...') #3 /var/www/html/test/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php(273): CodeIgniter\Autoloader\Autoloader->includeFile('/var/www/html/t...') #4 /var/www/html/test/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php(247): CodeIgniter\Autoloader\Autoloader->loadInNamespace('CodeIgniter\\CLI...') #5 [internal function]: CodeIgniter\Autoloader\Autoloader->loadClass( in /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php on line 162 I'm using DDEV with Docker to host it, webserver image using NGINX and PHP 7.4. I haven't expirenced any problems so far using this image in other projects. I have alredy tried fresh install, different version of PHP and nothing helped.
Hi,
have you found solution? Same here after updating from the v4.1.1. When I run "php spark serve" it works fine.
After some investigation I found that there are changes in system/Common.php for is_cli() method that cause current issue.
It's identified as CLI in condition: PHP Code: if (stristr(PHP_SAPI, 'cgi') && getenv('TERM')) because PHP_SAPI equals to fpm-fcgi and TERM variable equals to xterm. Is this correct behavior? How this should be fixed? (I am using docker with php-fpm and nginx.)
Your getting the errors because STDOUT is not defined, which could be your environment.
You can try adding these constants to see if it will work. PHP Code: if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'rb')); Try that. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
As I understand, the problem appears because request from browser incorrectly identified as CLI one. This is why those constants are undefined.
@InsiteFX, I tried to put those definitions. Now I receive blank page (with no errors). My solution is to put older version of is_cli() into app/Common.php, overriding updated one from system/Common.php. (I've taken it from https://github.com/codeigniter4/CodeIgni...Common.php.) PHP Code: function is_cli(): bool Now pages open fine.
Hi!
Your issue, along with some others, has a fix already in the provisional 4.2 branch.
[quote pid="389403" dateline="1629345651"]
Quote:Hi! [/quote] Hi, folks! Please, where's 4.2 branch?
You can always get the latest version of CodeIgniter from the GitHub Developer Page.
CodeIgniter 4 - Developer Version. CodeIgniter 4 web framework What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
10-15-2021, 04:26 PM
(This post was last modified: 10-15-2021, 04:48 PM by fagnerdin. Edit Reason: I removed the link from my previous answer. )
By the way, I discovered branch 4.2: "codeigniter4:4.2 - Make CLI detection as independent as possible from interface #4844"
Looks like this isn't accessible branch. I was facing this issue in a Docker container, I solved it using a ready-made solution from another professional (a Dockerfile). Thank you for your help. |
Welcome Guest, Not a member yet? Register Sign In |