-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question][Error] Namespace declaration statement has to be the very first statement #130
Comments
It's don't appear to be a PHP version's issue. Using the none@MacBook-Pro[~/D/w/middleware]:docker build . \
-f vendor/google/cloud-functions-framework/examples/hello/Dockerfile \
-t middleware
[+] Building 2.8s (13/13) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for gcr.io/gae-runtimes/php74:php74_20210216_7_4_15_RC00 0.4s
=> FROM docker.io/library/composer:1 1.2s
=> => resolve docker.io/library/composer:1 1.2s
=> [internal] load build context 0.3s
=> => transferring context: 776.00kB 0.3s
=> [stage-0 1/7] FROM gcr.io/gae-runtimes/php74:php74_20210216_7_4_15_RC00@sha256:b7d4aef9e57c17152c2ea9a3fbd04c23687fc93c7254608bdf6e19f14a7c10f3 0.0s
=> CACHED [stage-0 2/7] WORKDIR /srv/ 0.0s
=> CACHED [stage-0 3/7] RUN mkdir .googleconfig && echo '{"entrypointContents": "serve vendor/bin/router.php"}' > .googleconfig/app_start.json 0.0s
=> CACHED [stage-0 4/7] COPY composer.* ./ 0.0s
=> CACHED [stage-0 5/7] COPY --from=composer:1 /usr/bin/composer /usr/local/bin 0.0s
=> CACHED [stage-0 6/7] RUN composer install --no-dev 0.0s
=> [stage-0 7/7] COPY . . 0.6s
=> exporting to image 0.5s
=> => exporting layers 0.5s
=> => writing image sha256:5cfef36f6906e1cd8a829624d00f5153f33affb22740ae6189c42eaf5725405e 0.0s
=> => naming to docker.io/library/translation-middleware 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
then when I run the none@MacBook-Pro[~/D/w/middleware]:docker run -p 8080:8080 -e FUNCTION_TARGET=entryPoint middleware
[11-Jul-2022 14:37:05] WARNING: [pool app] child 28 said into stderr: "PHP message: PHP Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /srv/vendor/bin/router.php on line 12"
2022/07/11 14:37:05 [error] 30#30: *2 FastCGI sent in stderr: "PHP message: PHP Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /srv/vendor/bin/router.php on line 12" while reading response header from upstream, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/google-config/php-fpm.sock:", host: "localhost:8080" |
It's appear the first line in #!/usr/bin/env php // <-- this line
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../google/cloud-functions-framework/router.php)
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
include __DIR__ . '/..'.'/google/cloud-functions-framework/router.php'; when I remove this line, it's working. Perhaps, it's obviously not a solution to remove this line from vendor. Any help? |
I have the same error using the demo code, with or without Docker. The only way I found to use use my functions is to remove this line and commit the vendor folder... |
I've tried to troubleshoot this issue, without any luck. My temporary solution was to reference RUN mkdir .googleconfig && \
echo '{"entrypointContents": "serve vendor/google/cloud-functions-framework/router.php"}' > .googleconfig/app_start.json Also, |
the same issue in PHP 8.2.2 + Composer 2.5.2 |
Composer has an answer for this, seems like FF is improperly using the The composer coming from the GCP buildpacks for PHP are 2.1.3 which is before the 2.2.0 cutoff for these proxy files. So the solution (for local dev) is to change over to using the full path if you have a new composer version: php -S localhost:8080 vendor/google/cloud-functions-framework/router.php I'll go update the examples in a PR. |
Fixes #130: use full import paths from vendor for new composer Replace vendor/bin/router.php paths with the full router.php path in vendor/. Starting with composer 2.2, which is in package repos, composer changed the way it was handling the bin directive by creating wrapper files with shebangs in vendor/bin rather than symlinks. This caused our (incorrect) use of these bin/ files to break when they're used as a script from php because php expects the first entry in the file to be <?php when passed a script. The composer in the FF buildpacks is old enough that it doesn't introduce the shebang which is why it still works. I'm introducing tests to ensure we don't break that until we're safely upgraded the FF buildpack to use the correct router.
Hey,
Since I've updated my php version (
7.4.1
->7.4.30
) I am facing the following error :Is there a doc on this issue? I'm pretty sure I'm not the only one having this problem, but I can't find any troubleshooting.
Any help appreciated.
The text was updated successfully, but these errors were encountered: