Đừng quên đặt thời gian thực hiện tối đa thành vô hạn [0].
Tốt hơn hãy chắc chắn rằng bạn không chạy nhiều hơn một trường hợp, nếu đó là ý định của bạn:
ignore_user_abort[true];//if caller closes the connection [if initiating with cURL from another PHP, this allows you to end the calling PHP script without ending this one]
set_time_limit[0];
$hLock=fopen[__FILE__.".lock", "w+"];
if[!flock[$hLock, LOCK_EX | LOCK_NB]]
die["Already running. Exiting..."];
while[true]
{
//avoid CPU exhaustion, adjust as necessary
usleep[2000];//0.002 seconds
}
flock[$hLock, LOCK_UN];
fclose[$hLock];
unlink[__FILE__.".lock"];
Nếu ở chế độ CLI, chỉ cần chạy tệp.
Nếu trong một PHP khác trên máy chủ web, bạn có thể bắt đầu một loại phải chạy vô cùng như thế này [thay vì sử dụng Curl, điều này sẽ loại bỏ sự phụ thuộc]:
$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
Hoặc bạn có thể bắt đầu từ Linux Cron bằng cách sử dụng WGE như thế này:
`* * * * * wget -O - //localhost/infinite_loop.php`
Hoặc bạn có thể bắt đầu từ Trình lập lịch Windows bằng cách sử dụng Bitsadmin chạy tệp .bat có chứa điều này:
bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
16 năm trước
Ratty tại Brohoof dot com
10 năm trước
rsallo tại gna dot nospam dot es ¶
PHP tại DOT com tiêu tốn chứng khoán ¶
Alexander Dot Krause tại ed-solutions dot de ¶
[Php 4, Php 5, Php 7, Php 8]
set_time_limit - giới hạn thời gian thực hiện tối đa — Limits 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:
$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
0$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
1$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
2mba_aslam tại yahoo dot com ¶ ¶
15 năm trước
$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
3$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
4$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
5$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
6Jonathon Dot Keogh tại Gmail Dot Com ¶ ¶
14 năm trước
$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
7$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
8$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
9`* * * * * wget -O - //localhost/infinite_loop.php`
0Eric Pecoraro tại Shepard Com ¶ ¶
17 năm trước
`* * * * * wget -O - //localhost/infinite_loop.php`
1`* * * * * wget -O - //localhost/infinite_loop.php`
2`* * * * * wget -O - //localhost/infinite_loop.php`
3`* * * * * wget -O - //localhost/infinite_loop.php`
4`* * * * * wget -O - //localhost/infinite_loop.php`
5`* * * * * wget -O - //localhost/infinite_loop.php`
6Ẩn danh ¶ ¶
2 năm trước
`* * * * * wget -O - //localhost/infinite_loop.php`
7`* * * * * wget -O - //localhost/infinite_loop.php`
8`* * * * * wget -O - //localhost/infinite_loop.php`
9`* * * * * wget -O - //localhost/infinite_loop.php`
0Robertbrogers tại Gmail Dot Com ¶ ¶
8 năm trước
bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
1bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
2`* * * * * wget -O - //localhost/infinite_loop.php`
0mba_aslam tại yahoo dot com ¶ ¶
15 năm trước
bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
4Jonathon Dot Keogh tại Gmail Dot Com ¶ ¶
14 năm trước
bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
5bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
6`* * * * * wget -O - //localhost/infinite_loop.php`
0Eric Pecoraro tại Shepard Com ¶ ¶
17 năm trước
bitsadmin /create infiniteloop
bitsadmin /addfile infiniteloop //localhost/infinite_loop.php
bitsadmin /resume infiniteloop
8$cx=stream_context_create[
array[
"http"=>array[
"timeout" => 1, //at least PHP 5.2.1
"ignore_errors" => true
]
]
];
@file_get_contents["//localhost/infinite_loop.php", false, $cx];
4$seconds
0
$seconds
1Ẩn danh ¶ ¶
2 năm trước
$seconds
2
$seconds
3
$seconds
4
$seconds
5Robertbrogers tại Gmail Dot Com ¶ ¶
PHP tại Mightycpa.com
$seconds
6
$seconds
7
$seconds
8
`* * * * * wget -O - //localhost/infinite_loop.php`
019 năm trước ¶
15 năm trước
set_time_limit[20]
0
set_time_limit[20]
1
`* * * * * wget -O - //localhost/infinite_loop.php`
0Jonathon Dot Keogh tại Gmail Dot Com ¶ ¶
15 năm trước
set_time_limit[20]
3
set_time_limit[20]
4
`* * * * * wget -O - //localhost/infinite_loop.php`
0Jonathon Dot Keogh tại Gmail Dot Com ¶ ¶
14 năm trước
set_time_limit[20]
6
set_time_limit[20]
7
set_time_limit[20]
8
set_time_limit[20]
9Eric Pecoraro tại Shepard Com ¶ ¶
2 năm trước
seconds
0
seconds
1
seconds
2
`* * * * * wget -O - //localhost/infinite_loop.php`
0Robertbrogers tại Gmail Dot Com ¶ ¶
PHP tại Mightycpa.com
seconds
4
seconds
5
seconds
6
seconds
7
`* * * * * wget -O - //localhost/infinite_loop.php`
019 năm trước ¶
f.nakamura ¶
seconds
9
true
0
true
1
true
2
`* * * * * wget -O - //localhost/infinite_loop.php`
07 năm trước ¶
15 năm trước
true
4
true
5
true
6
true
7
true
8
true
9
false
0
false
1
false
2
`* * * * * wget -O - //localhost/infinite_loop.php`
0Jonathon Dot Keogh tại Gmail Dot Com ¶ ¶
f.nakamura ¶
false
4
7 năm trước ¶
2 năm trước
false
5
false
6
`* * * * * wget -O - //localhost/infinite_loop.php`
0Robertbrogers tại Gmail Dot Com ¶ ¶
PHP tại Mightycpa.com
false
8
false
9
`* * * * * wget -O - //localhost/infinite_loop.php`
019 năm trước ¶
PHP tại Mightycpa.com
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:
1
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:
2
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:
3
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:
4