Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sync belongsToMany throw allowed memory error #492

josearagon started this conversation in General
Discussion options

Describe the bug
Sync post relatedCategories throw PHP Fatal error: Allowed memory size of ********* bytes exhausted
Post is a cacheable model and category is a cacheable method.
It only pass in production envioronment.

When I try to update related categories from a post, I get a tipical memory error :(.

Eloquent Query
Please provide the complete eloquent query that caused the bug, for example:

public function relatedCategories()
 {
 return $this->belongsToMany(Category::class)->withTimestamps();
 }
$post-> relatedCategories()-> sync($request->related_categories);

Stack Trace
2020年09月07日 14:16:16 [error] 17231#17231: 59 FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 4096 bytes) in /CODE/www/.com/httpdocs_9d7999fc5ca37605867751000c54677cdfd1027c/vendor/predis/predis/src/Connection/StreamConnection.php on line 345
PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 16384 bytes) in /CODE/www/
.com/httpdocs_9d7999fc5ca37605867751000c54677cdfd1027c/vendor/symfony/error-handler/Error/FatalError.php on line 91" while reading response header from upstream, client: , server: *******.com, request: "PUT /360panel/posts/45530 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: ".com", referrer: "https://******.com/360panel/posts/45530/edit"

Environment

  • PHP: 7.3.9
  • Laravel: 7.27.0
  • Model Caching: 0.10.2
  • Redis.

Additional context
Add any other context about the problem here.

You must be logged in to vote

Replies: 4 comments

Comment options

@josearagon Please provide the full stack trace.

You must be logged in to vote
0 replies
Comment options

@mikebronner I just edited the original comment with the full stack trace.
Always need more memory. We try to increase memory_limit but it's never enough.

Thanks a lot

You must be logged in to vote
0 replies
Comment options

@josearagon Where are you getting this stack trace from? I'm looking for the full stack trace from /storage/logs/laravel.log. This seems to be only a partial stack trace.

You must be logged in to vote
0 replies
Comment options

Interestingly, Laravel rarely logs an error in this case. The error occurs at php level.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Converted from issue

This discussion was converted from issue #368 on March 05, 2025 13:50.

AltStyle によって変換されたページ (->オリジナル) /