Reputation: 766
I have a problem with my project, I want to use Monolog to write the logs and I can't do. So, I created an service :
services:
my_logger:
class: Monolog\Logger
arguments: [Debug]
calls:
- [pushHandler, [@my_log_handler]]
my_log_handler:
class: Monolog\Handler\StreamHandler
arguments: [/home/vagrant/Workspace/symfony/app/logs/test.log, 100]
My controller :
$em = $this->getDoctrine()->getManager();
$categories = $em->getRepository('EnsJobeetBundle:Category')->getWithJobs();
If I write :
$logger = $this->get('my_logger');
$logger->info('Test log');
The logs is inserted in test.log
If I write :
$logger = $this->get('my_logger');
$logger->info(print_r($categories,true));
The logs doesn't write. I get the error 500. Please help me. Thx in advance!!! Errors :
2015/03/05 12:58:48 [error] 4698#0: *76 FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 532676608 bytes)
PHP message: PHP 8. print_r() /home/vagrant/Workspace/symfony/src/Ens /JobeetBundle/Controller/JobController.php:34" while reading response header from upstream, client: 10.0.2.2, server: symfony.md, request: "GET
/job/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "symfony.dev:8000"
Upvotes: 2
Views: 2452
Reputation: 9647
You're running out of memory trying to process the array. That could be for many reasons, maybe it's just too big, maybe it has recursive aspects, etc.
A good trick when working with this is to just print the keys. You will see less data, but you will be much less likely to surpass your memory limits. When you get a look at your array, then you can print specific parts of it after you have a look at the keys. Try this:
$logger = $this->get('my_logger');
$logger->info(print_r(array_keys($categories),true));
Your other alternative, if you really need to see the whole array, it to increase your memory limits in php.ini. Look for a line like this to change them:
memory_limit = 128MB
Upvotes: 2