Setting up php-sdk-gae with symfony2 - php

I'm trying to run symfony2 with a hello world sample bundle inside php-sdk-gae.
I'm following the instructions provided in https://developers.google.com/appengine/docs/php/ and I can run the demo with the development controller (i.e: configuring app.yaml as following:
application: helloworld
version: 1
runtime: php
api_version: 1
handlers:
- url: /bundles
static_dir: helloWorld/web/bundles
- url: /favicon.ico
static_files: helloWorld/web/favicon.ico
upload: helloWorld/web/favicon.ico
- url: /.*
script: helloWorld/web/app_dev.php
It works fine, and I am able to get a Hello World after running the server and load /hello/World page
But when I try to run it with the production controller (app.php instead app_dev.php), I get an internal server error.
Request URL:http://mysite.local:8080/hello/World
Request Method:GET
Status Code:500 Internal Server Error
The only clue is in the console window where I launched the server, showing the lines ...
ERROR:root:php failure (255) with:
Status: 500 Internal Server Error
X-Powered-By: PHP/5.4.15
Content-type: text/html
If I make some changes in app.php files, I realize that it works fine with following AppKernel loading lines:
$kernel = new AppKernel('prod', true);
$kernel = new AppKernel('dev', false);
$kernel = new AppKernel('dev', true);
But not with the default configuration for the production enviroment ('prod',false).
I'm launching GAE server with this command:
google_appengine/dev_appserver.py --php_executable_path=/home/jon/php-sdk-gae/php-5.4.15/installdir/bin/php-cgi helloWorld/
I'm new in GAE, and I wonder Where can I find logs to get some more information about this error.

There is an uncaught exception in your production environment. Thats the reason for the http 500 error.
Let me quickly explain AppKernel::__construct
$kernel = new AppKernel($environment, $debug);
The first argument is the environment , the second one is the debug option.
If you set debug to true , symfony will try to catch exceptions and show you a nice stracktrace.
This covers the first and the third case where you don't get the http 500 error ( caused by an uncaught exception ).
$kernel = new AppKernel('prod', true);
$kernel = new AppKernel('dev', true);
Now you state the error is NOT thrown in dev environment with debug set to false.
$kernel = new AppKernel('dev', false);
This means in dev environment there is no exception.
Now you have to check the production log file to find out which exception has been thrown.
Use tail -f to see the live changes made to that file in your shell ( i.e. bash ) or if not available open the file in your editor and look for exceptions at the end.
tail -f app/logs/prod.log
In the symfony2 standard edition logfiles can be found at
app/logs/%kernel.environment%.log
... with %kernel.environment% being one of dev/prod/test

The problem is related with .htaccess file shipped with Symfony 2.2
I can use without any problem an application in symfony 2.0, and my application with Symfony 2.2 also works if I replace the web/.htaccess file shipped with Symfony 2.2 with the one shipped with Symfony 2.0
Maybe it is something related with the change made in order to avoid duplicate content (/app.php/something and /something), because since Symfony 2.2, /app.php redirects (301) the request.

I believe the problem is the lack of write support on the filesystem imposed by GAE. Also, symfony seems to rely on tempnam() function that's disabled in versions lower than 1.9.18 which is not public available at the moment I'm writing this.

There is also a problem with caching.
Maybe the problem is this, I've tried in localhost a project with developement version, all right. And when it's deployed to GAE it fails.
Maybe that helps.
http://www.ideato.it/planet-ideato/symfony2-su-google-app-engine/

Related

kernel interface not handled request in laravel

I have one running project on LIVE server and I have just download it and try to run in the localhost,
but it gives error
This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
I have started to debug step by step from index.php by adding exit()
i have reach to public/index.php and inside that the ERROR comming from
$response = $kernel->handle(
$request = Request::capture()
)->send();
I have check the $request it was giving the response but $kernel->handle is not handling the request as i think.
Please guide me on this what should I approach next?
Can you check the storage/logs/laravel.log file? This file may give you a better idea of the actual issue.
One more thing you can try running the composer dumpautoload command.

Symfony doesn't give full traces of Exceptions in production

We recently moved our infra to K8s, and since I have issue to get Traces of my Exceptions
We're on Symfony 3.4, and my Exception traces only gaves me web/app.php, but not root cause
Error: Call to a member function send() on null
#0 web/app.php(19): null
app.php is classic Symfony file, nothing relevent inside:
$kernel = new AppKernel('prod', false);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I tried to connect my localhost to my production DB, to see if I had the same issue, but no. I have correct full trace of my Exception
If I try in production with "app_dev.php" (which I enabled only for this test), I have same issue with no trace
Do you know what could cause this issue?
A PHP configuration? I checked differences between php -i on previous infra & new one, but I don't see any relevant difference
Edit:
Monolog in config.yml:
monolog:
handlers:
main:
type: rotating_file
max_files: 10
path: '%kernel.logs_dir%/%kernel.environment%.general.log'
level: INFO
formatter: myapp.monolog.formatter.json_message
Edit 2:
We bring part of old infra alive. And here the difference :
Old infra, for Fatal Errors, we have the full trace:
On new infra, same fatal error is displayed without any more detail
The issue seems to comes from datadog agent that we added on our new infra.
Edit: Issue has been fixed in https://github.com/DataDog/dd-trace-php/releases/tag/0.79.0

How to set up a staging environment based on a symlink to prod configuration, without showing debug information?

I would like to setup a staging environment with the same configuration as the prod environment.
According to the docs, I proceed as follow:
I create a staging symlink that points on prod
configure the env in .env: APP_ENV=staging
clear the cache: php bin/console cache:clear
ask for an URL that does not exist to trigger a 404 error: http://localhost:8080/an-url-that-does-not-exists
When the APP_ENV=prod, my custom error page is render properly, but when APP_ENV=staging, the debug message NotFoundHttpException is rendered?
The profiler is not displayed.
What am I missing?
tldr;
Crate an .env.staging file and use it to set APP_DEBUG to 0. Debug mode and environment are set independently.
By default, unless you set it explicitly debug mode (APP_DEBUG) is set from the environment automagically.
This happens in the following steps:
In your front-controller (index.php, usually) you would find this line:
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
And on DotEnv::bootEnv() you'll find this:
$debug = $_SERVER[$k] ?? !\in_array($_SERVER[$this->envKey], $this->prodEnvs, true);
This will compare your APP_ENV with an array of "environments" that DotEnv, considers "production-like". By default, this array includes only prod.
You could modify the instance of the DotEnv by calling setProdEnvs():
(new Dotenv())
->setProdEnvs(['prod', 'staging'])
->bootEnv(dirname(__DIR__).'/.env');
... but generally simply disabling debug mode on your .env file would be enough.

Symfony: disable exceptions in prod mode

I'm a beginner with Symfony.
I have a Symfony 3.1 project. I put y project on my remote server. Everything works fine. Then I use SensioLabsInsight to check errors in my project. This analyse tool gives me those 2 warnings messages
:
"Exceptions should not be enabled in production" and "Symfony applications should not contain a config.php file"
Then my first question is how can I disable Exceptions in production ?
My second question is may I remove the config.php file in production (located in myBundle/web/config.php) ?
Then my first question is how can I disable Exceptions in production ?
As far as I can see when searching this on Google, I think it's because the second parameter passed to new AppKernel('prod', ...); is true, which enables debug mode. Set it to false. (same applies to debug settings in config_prod.yml).
My second question is may I remove the config.php file in production (located in myBundle/web/config.php) ?
Yes, also remove any front-controller (like app_dev.php) except from your production one. Remember: The standard edition is just a recommendation. Symfony doesn't force you any file or directory in the directory structure.
In the new Symfony version, there is a new var APP_DEBUG, which you send to Kernel in the second parameter.
Just add new var to your .env file
APP_DEBUG=false
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

Google App Engine PHP CodeIngiter "Error: Server Error" (500 Server Error) logged as Error Code 204

Running PHP (CodeIgniter) on Google App Engine, about a third of the time when the page loads the following error occurs...
500 Server Error
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
..and in the app engine log:
A problem was encountered with the process that handled this request, causing it to exit. This is likely to cause a new process to be used for the next request to your application. (Error code 204)
On-refresh the page loads correctly about 2 out of 3 times. Configuration settings:
php.ini
google_app_engine.enable_functions = "php_sapi_name, gc_enabled"
display_errors = on
allow_url_fopen = on
apc.cache_by_default = 0
apc.enabled = 0
app.yaml
application: APP_NAME_ABC123
version: 1
runtime: php
api_version: 1
handlers:
- url: /img
static_dir: img
- url: /app
static_dir: app
- url: /
script: index.php
- url: /.*
script: index.php
I tested CodeIgniter v2.1 and v3 on app engine and got this error as well.
It happens when using $autoload['libraries'] = array('database');
Then after a few random page refreshes this error pops up.
After changing the following in database.php:
'pconnect' => TRUE,
into
'pconnect' => FALSE,
This errors is gone in my application.
Now both version 2.1 and 3 are working for me.
If you are using App Engine instance with Cloud SQL please remember that App Engine cannot have more than 12 concurrent connections to a Cloud SQL instance. So, you need to close the any established connections before processing a request. If you do not do this it will cause a leak may eventually new connection to fail. And that could be one of the reason why you are getting 204 error. I suggest not to use persistent connection by putting persistent attribute false. (As for example if you use PHP Data Object to connect your SQL you can set PDO::ATTR_PERSISTENT => FALSE)
In case of CodeIgniter in the DB Settings sections of your database.php file you can change the line $db['production']['pconnect'] = TRUE; to $db['production']['pconnect'] = FALSE; and see if it works or not.
That has been a pesky, intermittent issue on App Engine for a few years. Google "app engine (Error code 204)" and you'll see others with the same issue. Not sure a user-side solution has ever been found. Try changing your version number and redeploying. Destroy any open instances in the console.

Categories