php에서 실행 시간 초과를 늘리는 방법
트랜잭션 타임아웃을 늘리는 방법동영상을 업로드하고 싶은데 큰 사이즈의 동영상이 업로드되지 않았습니까?
가 The process *** exceeded the timeout of 60 seconds.
php.ini 설정을 변경해야 합니다.
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds
PHP.ini의 위치는 시스템 환경에 따라 달라집니다.상세한 것에 대하여는, http://php.net/manual/en/ini.list.php 를 참조해 주세요.
실행 시에도 사용할 수 있어야 합니다.
set_time_limit(100);
http://php.net/manual/en/function.set-time-limit.php
또는 vhost-config에서
php_admin_value max_execution_time 10000
신뢰성이 낮은 애플리케이션의 성능에는 글로벌 실행 시간 제한을 낮게 설정하는 것이 좋습니다.따라서 이러한 스크립트는 반드시 실행해야 하는 시간만큼만 실행할 수 있습니다.
p.s.: post_max_size 및 upload_max_filesize를 잊지 마십시오(첫 번째 답변이 이미 나와 있습니다).
Hannes의 답변을 완성하기 위해.
php.ini 설정을 변경해야 합니다.
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must
무제한을 원하는 경우(이유는 모르겠지만 원하는 경우) 시간을 0으로 설정할 수 있습니다.
php.ini 설정을 변경해야 합니다.
upload_max_filesize = 0
max_execution_time = 0
php.ini가 어디에 있는지 모르는 경우.서버에서 "name.php" 파일을 실행하여 다음 파일을 저장할 수 있습니다.
<?php phpinfo(); ?>
그리고 웹사이트에서 php.ini의 설정을 볼 수 있으며 어디에 있는지 표시됩니다.
2015년 1월 9일 편집:
php.ini에 액세스할 수 없는 경우 두 가지 옵션이 더 있습니다.
이 행은 "name.php" 파일에서 직접 설정할 수 있지만 이 옵션의 upload_max_filesize는 찾을 수 없습니다.
set_time_limit(0);
또는 ".htaccess"에서
php_value upload_max_filesize 0
php_value max_execution_time 0
필요한 것이 1~2페이지만 한정되어 있다면 어플리케이션 전체에 영향을 주지 않도록 set_time_limit을 사용하는 것이 좋습니다.
set_time_limit(some_values);
단, 이 2가지 값(post_max_size & upload_max_filesize)은 조사 대상이 됩니다.
ini_set 함수를 통해 설정할 수 있습니다.
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','2M');
또는 Hannes의 위와 같은 응답으로 php.ini 파일에 직접 저장하거나, 심지어 아래와 같이 .htaccess로 설정합니다.
php_value upload_max_filesize 2M
php_value post_max_size 20M
Microsoft IIS 서버를 사용하고 있는 경우는, 다른 유저가 말한 php.ini 설정 외에, IIS 서버 매니저에서 PHP Fast CGI 애플리케이션의 실행 타임 아웃 설정을 늘릴 필요가 있습니다.
순서 1) IIS 서버 매니저를 엽니다(보통 [시작]메뉴의 [서버 매니저], [툴/인터넷 정보 서비스(IIS) 매니저]의 순서로).
스텝 2) 메인 접속을 클릭합니다(특정 도메인에 한정되지 않음).
순서 3) [IIS]섹션에서 [Fast CGI Settings](Fast CGI 설정)을 찾습니다(아래 참조).
스텝 4) 여기서 PHP 어플리케이션을 오른쪽 클릭하여 [Edit...]를 선택합니다.
5단계) 타임아웃을 확인합니다(아래 참조).
제 경우 기본 타임아웃은 70초와 90초였습니다.그 중 전자는 PHP 스크립트에서 500의 내부 서버 오류를 발생시켜 70초 이상 걸렸습니다.
위의 답변에 덧붙여, 다음을 사용할 수 있습니다.set_time_limit()
기능:
http://php.net/manual/en/function.set-time-limit.php
통과.0
인수를 지정하면 스크립트가 시간 제한 없이 실행됩니다.
(예를 들어 서버에서) php.ini를 편집할 수 없는 경우 php 코드 내에서 php.ini 파라미터를 변경할 수 있습니다.시험:
ini_set('max_execution_time', 'NUMBER OF SECONDS TO ALLOW BEFORE TIMEOUT');
그래도 되지 않는 경우는, 같은 방법으로 「set_time_limit」를 설정해 주세요.그 이외의 옵션은 호스트에 문의하는 것뿐입니다.안전 모드에서는 이러한 설정을 수정할 수 없습니다.
입력 오류: ini_set('max_input_time' '200M') - 값 집합은 ini_set('max_input_time' '200')과 같이 int여야 합니다.
특히 PHP 타임아웃에 대해 질문하고 있는 것은 알고 있습니다만, 그 외에는 아무도 언급하지 않은 것 같습니다.웹 서버에도 타임아웃이 있을 수 있고, PHP 타임아웃과 매우 비슷해 보일 수 있습니다.
이 때문에, 다음과 같습니다.
- max_syslog_time = {초 단위(1분 동안 60초)} 행을 추가하여 php.ini의 시간 초과 증가
- ini_set('max_execution_time'', {초수, 즉 1분간 60')을 추가하여 스크립트 자체의 타임아웃을 늘립니다.
또한 phpinfo() 함수로 max_execution_time이 실제로 증가했음을 확인하고 Apache 자체가 타임아웃되지 않도록 하기 위해 .htaccess에 추가할 수 있습니다.
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
자세한 내용은 이쪽:https://www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/
첫 번째 체크는php.ini
파일 경로phpinfo()
;이후변경되었습니다.PHP.INI
파라미터:
upload_max_filesize = 1000M
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 30
Apache 재부팅
set_time_limit(0); // safe_mode is off
ini_set('max_execution_time', 500); //500 seconds
주의: 명령어를 사용하여 다음을 찾을 수도 있습니다.php.ini
Linux의 경우
locate `php.ini`
사용자가 안전 모드인지 테스트합니다. 그렇지 않은 경우 시간 제한(로컬 값)을 원하는 값으로 설정합니다.
if(!ini_get('safe_mode')){
echo "safe mode off";
set_time_limit(180);// seconds
phpinfo();// see 'max_execution_time'
}
*세이프 모드가 'ON'인 경우에는 이 방법으로 시간 제한을 설정할 수 없습니다.
옵션: php.ini에 대한 구성을 설정했지만 업로드할 수 없는 경우
- 에러 코드를 체크하는 php 함수입니다.
$error_type = [];
$error_type[0] = "There is no error";
$error_type[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
$error_type[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
$error_type[3] = "The uploaded file was only partially uploaded.";
$error_type[4] = "No file was uploaded.";
//$error_type["5"] = "";
$error_type[6] = "Missing a temporary folder. Introduced in PHP 5.0.3.";
$error_type[7] = "Failed to write file to disk. Introduced in PHP 5.1.0.";
$error_type[8] = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.";
//------------------------------
//--> show msg error.
$status_code = $_FILES["uploadfile"]["error"];
if($status_code != 0){
echo $error_type[$status_code];
exit;
}
실행 할 수 ..htaccess
삭제:
php_value max_execution_time 180
시간 제한을 늘리려면 먼저 현재 값을 얻는 것이 좋습니다. set_time_limit
을 사용법 값들어 "from"(from: from))의php.ini
에 설정된 값)이.set_time_limit
, 제한 시간을 줄여줍니다!
그럼 왜 이렇게 작은 도우미를 데리고 있는 거죠?
/**
* @param int $seconds Time in seconds
* @return bool
*/
function increase_time_limit(int $seconds): bool
{
return set_time_limit(max(
ini_get('max_execution_time'), $seconds
));
}
// somewhere else in your code
increase_time_limit(180);
다음 항목도 참조하십시오.PHP 스크립트에서 max_execution_time 가져오기
언급URL : https://stackoverflow.com/questions/3829403/how-to-increase-the-execution-timeout-in-php
'programing' 카테고리의 다른 글
데이터베이스 복원 시 이모티콘이 유지되지 않음 (0) | 2022.10.12 |
---|---|
mariaDB, 여러 테이블에서 삭제가 정말 안전합니까? (0) | 2022.10.12 |
JavaScript에서 랜덤 문자열/문자 생성 (0) | 2022.10.12 |
고정폭 정수형(예: uint8_t)을 사용하지 않는 이유가 있습니까? (0) | 2022.10.12 |
Python에서 날짜를 datetime으로 변환 (0) | 2022.10.12 |