php max_execution_time 및 mysql 등 시간제어

HYEONG HWAN, MUN/ 2월 13, 2023/ 미분류/ 0 comments

https://blog.lael.be/post/11645

관련 정의는 다음과 같다.

https://www.php.net/manual/en/info.configuration.php#ini.max-execution-time

 

max_execution_time int
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.

On non Windows systems, the maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

 

이 시간은 PHP의 스크립트 실행시간을 제한한다. 다만 외부 시스템콜 (mysql 쿼리등) 실행시간 동안에는 제어권이 넘어가기 때문에(=완료될때까지 대기하기 때문에), 이 제한에 영향을 받지 않는다.

이 글을 쓰는 이유인데, max_execution_time 에 대해서, 내가 잘못 이해한 내용이 있어서 남겨보도록 한다.

 

만약 max_execution_time 을 300초로 지정하였고,

[PHP 스크립트 200초] [MYSQL 쿼리 500초] [PHP 스크립트 200초] 의 실행 계획이 있다면, MYSQL 쿼리가 끝난 700초 시점에 실행이 중단되게 된다. (시스템콜이 끝나고 제어권이 돌아온 순간)
나는 지금까지 max_execution_time 에서 외부 시스템콜의 시간을 제외하고 측정하는 줄 알았다. 즉 위의 실행계획에서 이전에 200초를 썼으니까, MYSQL 후에 100초를 더 쓸 수 있을 것이라고 생각하였다.
그런데 시스템콜에서 제어권이 돌아오자마자 중단시키더라.

한줄 요약 : 시스템콜(mysql 실행) 시간도 max_execution_time 에 합산하여 측정된다.

 

추가 팁 : MYSQL 5.7 부터 동일한 서버 변수가 추가되었다.

https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html

SELECT 구문에 대해서 서버에서 종료(kill)할 수 있게 되었다. 설정하면 많은 도움이 될듯함.

 

Leave a Comment

작성하신 댓글은 관리자의 수동 승인 후 게시됩니다.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*