headers_sent() returns true in php-cli mode
What happened?
I'm running (trying) to run NextCloud on FrankenPHP, which has been working for the most part, but when running the included Console script, I get a syntax error that there is content before the <?php section and should be removed. But there isn't.
Added by @withinboredom:
<?php
var_dump(headers_sent());
headers_sent() returns true in cli-mode.
Build Type
Official static build
Worker Mode
No
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
Please see [phpinfo.php](https://nextcloud.jschneiderprojects.au/phpinfo.php)
Please let me know when you have viewed this, so I can take it down
Relevant log output
$ docker exec -it jcake-nextcloud-1 frankenphp php-cli /app/occ files:scan
An unhandled exception has been thrown:
Exception: Config file has leading content, please remove everything before "<?php" in config.php in /app/lib/private/Config.php:257
Stack trace:
#0 /app/lib/private/Config.php(71): OC\Config->readData()
#1 /app/lib/base.php(150): OC\Config->__construct('/app/config/')
#2 /app/lib/base.php(622): OC::initPaths()
#3 /app/lib/base.php(1181): OC::init()
#4 /app/console.php(48): require_once('/app/lib/base.p...')
#5 /app/occ(11): require_once('/app/console.ph...')
#6 {main}
But there isn't.
There may very well be hidden data that you cannot see in your text editor (non-printable characters, for example) or maybe whatever is reading the config is misinterpreting a BOM. Also, if there are any PHP errors in your config, it's possible it will detect this as input because PHP is outputting the error/warning.
This seems more like a nextcloud issue and not a frankenphp issue. Closing this.
Hi I forgot to link the thread from the Nextcloud support forums. There are no non-printable characters. I proved this using a hexdump.
Updated the context to include the actual bug
Updated the context to include the actual bug
Ah apologies... That would have been useful..
Actually it's more a workaround than anything but in Nextcloud server source you can comment lines between 216 and 223 in lib/private/Config.php and you won't be bothered anymore.
Actually it's more a workaround than anything but in Nextcloud server source you can comment lines between 216 and 223 in
lib/private/Config.phpand you won't be bothered anymore.
my god. Even if it's a workaround it works! Thank uuu
Is there any special character in these lines?
Nah it's just a check.
if (!defined('PHPUNIT_RUN') && headers_sent()) { // syntax issues in the config file like leading spaces causing PHP to send output
$errorMessage = sprintf('Config file has leading content, please remove everything before "<?php" in %s', basename($file));
if (!defined('OC_CONSOLE')) {
print(\OCP\Util::sanitizeHTML($errorMessage));
}
throw new \Exception($errorMessage);
}
Hi,
Thanks for your work on FrankenPHP! I’m really looking forward to try it out - I just haven’t had the chance yet.
I've sent J-Cake to frankenphp because "headers_sent()" does return true even for cli requests.
Here’s what I’ve noticed so far:
- The Docker image (8cd0c8a23307) either seems fixed or was never affected.
- However, I can still reproduce the issue by running
frankenphp php-cli test.php(v1.4.2 on linux).
test.php:
<?php
var_dump(headers_sent());
Hope this helps!
Ok, it's in CLI mode! I missed that. We likely have a bug for this.
Any news on this? Its still happening in frankenphp v1.9.0 A fix would be greatly appreciated!
We're working on getting cli-mode to actually use the php-cli in 8.5 ... it's non-trivial (because php-cli adds some functions that shouldn't be available in other sapis) but it is in-progress.
Good to know, thank you for the information