PHP/Error

Laravel 502 Bad Gateway, route:list Allowed memory size error

DSeung 2022. 7. 14. 14:56

에러 상황

1. Ajax 요청 및 관리자 단을 들어가는 등 모델 사용 시 아래와 같은 에러 발생

2. ssh에서 php artisan route:list 입력 시 
PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in 에러 발생

 


시도

- vagrant의 xdebug 설정을 다 주석처리 

- homestead.yamll의 맵핑에 type:apache로 변경하기

 

를 시도해보았으나 nginx나 설정의 문제가 아닌 코드 상의 에러였습니다

 


해결

설정을 바꾸지 않았는데 단순히 502 에러라는 이유로 서버나 설정이 원인인 걸로 오해해서 8시간을 날렸네요

 

php artisan route:list 에서 나올 수 없는 사이즈가 나온 걸로 보아 재귀 실행이 된 걸로 보았습니다.

아래 코드에서 조건문 때문에 생성자 실행이 항상 되지 않을 거라 보았는데, this를 쓰는 순간 생성자가 실행돼서 재귀적으로 실행되었습니다.

 

조심해야겠네요

 

    public function __construct(){
        parent::__construct();
        $this->init();
    }

    public function init(){
        $date = Carbon::now()->format('Y-m-d 00:00:00');
        if($this->where('setting_on', $date)->first() === null){
            $new['setting_on'] = $date;
            $this->create($new);
        }
    }
반응형