X
X
xenonhammer2020-02-16 20:24:04
PHP
xenonhammer, 2020-02-16 20:24:04

Why does json_decode cause Fatal error?

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 79 bytes)
The most surprising thing for me is that if you run it through a browser, then everything is done.
But when I execute through the console, a fatal error appears pointing to this line of code.
I get a multi-dimensional array via API.
Why does everything in the browser perform then? and how to deal with it
$data = json_decode($result);

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2020-02-16
@Firsov36

The error indicates that there is not enough memory to process the request. Most likely you have some php settings for the site, and others for the console. Maybe even PHP versions are different. Check this point first.

M
Melkij, 2020-02-16
@melkij

The most surprising thing for me is that if you run it through a browser, then everything is done.
But when I execute through the console, a fatal error appears pointing to this line of code.

Why did you decide that they should have identical configs? On the contrary, configs are usually different.
Well, the error has nothing to do with json. If the memory_limit allocated by the PHP core. Wherever you exceed it, you will get a fatal error, it's simple. And there are only two ways from here: try to reduce the memory consumption of the script or raise the limit.

P
profesor08, 2020-02-16
@profesor08

Set `memory_limit` in php.ini . The php that processes requests from the web server can pull up another config. Or even different versions of PHP. Make sure that the correct PHP version is running in the console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question