For debugging purposes I want to log all headers from the response object like so in filters.php:
App::after(function($request, $response) {
if(App::environment() !== 'dev') { return; }
error_log(print_r($response->getHeadersPleaaase()));
$response is typically a Illuminate\Http\JsonResponse and I cannot find any obvious method for getting the headers there.
Headers is a public property:
error_log(print_r($response->headers));
ini_set("log_errors", 1);
ini_set("error_log", __DIR__.'/../app/logs/prod.log');//ini_set("error_log", your path and file);
error_log( 'BEGIN===========>' );
error_log( $request );
error_log( $response );
error_log( '<========END' );
an example of using (Symfony2)
app.php
<?php
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$apcLoader = new ApcClassLoader('sf2', $loader);
$loader->unregister();
$apcLoader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
ini_set("log_errors", 1);
ini_set("error_log", __DIR__.'/../app/logs/prod.log');
error_log( 'BEGIN===========>' );
error_log( $request );
error_log( $response );
error_log( '<========END' );
$response->send();
$kernel->terminate($request, $response);
Related
I have been trying to install Mapbender for several days but in the end I have either this message or the other
http://localhost/mapbender/app_dev.php/manager/applications
Not Found
The requested URL was not found on this server.
Apache/2.4.41 (Ubuntu) Server at localhost Port 80
OR
<?php
use Symfony\Component\HttpFoundation\Request;
$loader = require_once(__DIR__ . '/../app/autoload.php');
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('prod', false);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I worked on a symfony 3 project that an ex-colleague set up.
I'm beginner with Symfony.
I don't know how to autoload data (parameters) from database to set in php constants
The app begin in this file : /web/app_matnat_dev.php
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
require_once 'access_control.inc.php';
ini_set("error_reporting", E_ALL);
ini_set("display_errors", "1");
/**
* #var Composer\Autoload\ClassLoader $loader
*/
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel($_SERVER['SFENV'], true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
try {
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
} catch (Exception $e) {
var_dump($e);
}
It includes /app/autoload.php :
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
* #var ClassLoader $loader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
/* Ensemble de fonctions dont j'ai besoin */
require_once __DIR__.'/../src/RecupBundle/env.php';
require_once __DIR__.'/../src/RecupBundle/autoload_orm.php';
//require_once __DIR__.'/../src/RecupBundle/constants.php';
require_once __DIR__.'/../src/RecupBundle/functions.php';
return $loader;
That's here i'd like (i think i can) to load from database my parameters and after include others parameters
require_once __DIR__.'/../src/RecupBundle/constants.php';
i call a method in first lines in this file
// database parameters to constants
use function RecupBundle\ORM\param;
RecupBundle\ORM\param()->load();
But i've this error
Notice: Undefined index: db_link in /src/RecupBundle/ORM/db_query.php on line 44
Because db_link is only defined in /web/app_matnat_dev.php when i do that $response = $kernel->handle($request);
I need help :)
Thanks
I've found a trick: I do request just after the connexion to the database.
So, I can define the constants used everywhere in the project.
i have uploaded my laravel project to live server but its not working when i track code i get the execption that class request does not exists,please help me to find out the error
this is my file
index.php
<?php
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app->bind('path.public', function() {
return __DIR__;
});
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
try{
$request = App\Http\Request::capture()
}
catch(Exception $e)
{
echo "error:".$e->getMessage()."<br>";
}
$response = $kernel->handle(
$request = App\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Request facade usually lives in a different namespace. Try replacing any reference to
App\Http\Request
with just
Request
in order to access the facade by its global namespace alias.
I was wondering if there is any possibility to define multiple environments in Symfony's app.php?
src/web/app.php:
$kernel = new AppKernel('benchmark', false);
$kernel = new AppKernel('benchmark,dev', false); // < Incl. the dev tools
Why do I ask? Isn't this a stupid question? Because the default check syntax seems to support multiple environments in_array() or do I misinterpret something here?
src/app/AppKernel.php:
if (in_array($this->getEnvironment(), array('dev'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
...
}
The "check" in the app/AppKernel is here to check if there are some bundles you want available in several environments, such as "test" or "dev" for example.
you could then have in your AppKernel following lines :
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new My\Bundle\Uber\MyUberBundle();
...
}
that will enable this example bundle in both dev and test environments.
So the app.php doesn't support multiple environment definitions. If you want several envs you can still define new files as app.php and app_dev.php :)
For example an admin.php with itself look something like
<?php
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('admin', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I would like to preapare the app.php file with Symfony 2.1 and APC. I took the Symfony standard edition configured it with doctrine and then made changes described here:
http://symfony.com/doc/2.1/book/performance.html
<?php
require_once __DIR__.'\..\vendor\symfony\symfony\src\Symfony\Component\ClassLoader\UniversalClassLoader.php';
require_once __DIR__.'\..\vendor\symfony\symfony\src\Symfony\Component\ClassLoader\ApcUniversalClassLoader.php';
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
?>
but it is not working, I got error:
Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in __my_path__\app\AppKernel.php on line 7
How should I prepare the app.php for best performance.
Take a look at the default app.php file in the Symfony Standard Distribution. In order to enable APC your app.php file should look like this:
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
You can also improve performance if you enable the symfony gateway cache by uncommenting the require_once __DIR__.'/../app/AppCache.php'; and $kernel = new AppCache($kernel); lines.