TAILIEUCHUNG - Advanced PHP Programming- P4

128 Chapter 5 Implementing with PHP: Standalone Scripts if($i++ == 10) { break; } } print “\n\n”; } ? The script works by reading in a logfile on STDIN and matching each line against $regex to extract individual script then computes summary statistics, counting the number of requests per unique IP address and per unique Web server user agent. Because combined-format logfiles are large, you can output a . to stderr every 1,000 lines to reflect the parsing progress. If the output of the script is redirected to a file, the end report will appear in the file, but the .’s will. | 128 Chapter 5 Implementing with PHP Standalone Scripts if i 10 break print 11 n n The script works by reading in a logfile on STDIN and matching each line against regex to extract individual fields. The script then computes summary statistics counting the number of requests per unique IP address and per unique Web server user agent. Because combined-format logfiles are large you can output a . to stderr every 1 000 lines to reflect the parsing progress. If the output of the script is redirected to a file the end report will appear in the file but the . s will only appear on the user s screen. Parsing Command-Line Arguments When you are running a PHP script on the command line you obviously can t pass arguments via _GET and _POST variables the CLI has no concept of these Web protocols . Instead you pass in arguments on the command line. Command-line arguments can be read in raw from the argv autoglobal. The following script usr bin env php php print_r argv when run as this . foo bar barbara gives the following output Array 0 1 foo 2 bar 3 barbara Notice that argv 0 is the name of the running script. Taking configuration directly from argv can be frustrating because it requires you to put your options in a specific order. A more robust option than parsing options by hand is to use PEAR s Console_Getopt package. Console_Getopt provides an easy interface to use to break up command-line options into an easy-to-manage array. In addition to Parsing Command-Line Arguments 129 simple parsing Console_Getopt handles both long and short options and provides basic validation to ensure that the options passed are in the correct format. Console_Getopt works by being given format strings for the arguments you expect. Two forms of options can be passed short options and long options. Short options are single-letter options with optional data. The format specifier for the short options is a string of allowed tokens. Option letters can be followed with a .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.