PHP에서 특정 시간이 지나면 함수 실행을 중지합니다.

PHP에서 특정 시간이 지나면 함수 실행을 중지합니다.

exec()내 스크립트에는 다섯 가지 기능이 있습니다 . 함수가 주어진 시간 내에 응답하지 않으면 해당 함수가 종료되고 다음 함수가 실행을 시작하도록 설정하고 싶습니다.

<?php
    exec("timeout 5 /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);  
    exec("timeout 5 /usr/local/bin/trun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);  
    exec("timeout 5 /usr/local/bin/drun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
 ?> 

timeout주장은 작동하지 않습니다. 이 문제를 수정하거나 다른 방법을 알려주십시오.

답변1

당신의 exec sysntax가 잘못되었습니다

string exec ( string $command [, array &$output [, int &$return_var ]] )

코드를 시작하기 전에 다음과 같이 시간 제한을 설정해야 합니다.

<?php

set_time_limit(5);

exec(" /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
?>

관련 정보