Hướng dẫn php set_time_limit - php set_time_limit

[Php 4, Php 5, Php 7, Php 8]

set_time_limit - giới hạn thời gian thực hiện tối đaLimits the maximum execution time

Sự mô tả

set_time_limit [int $seconds]: bool[int $seconds]: bool

Khi được gọi, set_time_limit [] khởi động lại bộ đếm thời gian chờ từ 0. Nói cách khác, nếu thời gian chờ là 30 giây mặc định và 25 giây vào thực hiện tập lệnh, một cuộc gọi như set_time_limit[20] được thực hiện, tập lệnh sẽ chạy trong tổng số 45 giây trước khi hết thời gian.set_time_limit[] restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit[20] is made, the script will run for a total of 45 seconds before timing out.

Thông số

seconds

Thời gian thực hiện tối đa, tính bằng giây. Nếu được đặt thành 0, không có giới hạn thời gian được áp đặt.

Trả về giá trị

Trả về true khi thành công, hoặc false về thất bại.true on success, or false on failure.

Ghi chú

Ghi chú::

Hàm set_time_limit [] và chỉ thị cấu hình MAX_EXECATED_TIME chỉ ảnh hưởng đến thời gian thực hiện của chính tập lệnh. Bất kỳ thời gian nào dành cho hoạt động xảy ra bên ngoài việc thực thi tập lệnh như các cuộc gọi hệ thống bằng hệ thống [], hoạt động luồng, truy vấn cơ sở dữ liệu, v.v. không được bao gồm khi xác định thời gian tối đa mà tập lệnh đã chạy. Điều này không đúng trên các cửa sổ trong đó thời gian đo là có thật.set_time_limit[] function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system[], stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

kexianbin tại DIYism dot com ¶

8 năm trước

Both set_time_limit[...] and  ini_set['max_execution_time',...]; won't count the time cost of sleep,file_get_contents,shell_exec,mysql_query etc, so i build this function my_background_exec[], to run static method/function in background/detached process and time is out kill it:

my_exec.php:

Bài Viết Liên Quan

Chủ Đề