실행시 설정

이 함수의 작동은 php.ini 설정에 영향을 받습니다.

파일시스템과 스트림 설정 옵션
이름 기본값 변경권한 변경점
allow_url_fopen "1" PHP_INI_ALL PHP <= 4.3.4에서 PHP_INI_ALL. PHP < 6에서 PHP_INI_SYSTEM. PHP 4.0.4부터 사용 가능.
allow_url_include "0" PHP_INI_ALL PHP 5에서 PHP_INI_SYSTEM. PHP 5.2.0부터 사용 가능.
user_agent NULL PHP_INI_ALL PHP 4.3.0부터 사용 가능.
default_socket_timeout "60" PHP_INI_ALL PHP 4.3.0부터 사용 가능.
from "" PHP_INI_ALL  
auto_detect_line_endings "0" PHP_INI_ALL PHP 4.3.0부터 사용 가능.

위 설정 지시어에 대한 간단한 설명입니다.

allow_url_fopen boolean

이 옵션은 URL 객체에 파일처럼 접근할 수 있는 URL-판단 fopen 랩퍼를 활성화합니다. 기본 랩퍼는 ftp나 http 프로토콜을 사용하여 원격 파일의 접근을 제공하며, zlib 등의 몇몇 확장은 추가 랩퍼를 등록합니다.

Note:

보안을 위해, 이 옵션은 php.ini에서만 설정할 수 있습니다.

Note:

이 옵션은 버전 4.0.3 릴리즈 후에 추가되었습니다. 버전 4.0.3과 이전 버전에서 이 기능을 무효화 하려면 설정 스위치 --disable-url-fopen-wrapper를 사용하여 컴파일해야만 했습니다.

Warning

윈도우 버전 PHP 4.3.0 이전에는, 다음 함수는 원격 파일 접근을 허용하지 않습니다: include, include_once, require, require_once, 그리고 GD and Image 함수 목록 확장의 imagecreatefromXXX 함수.

allow_url_include boolean

이 옵션은 다음 함수에서 URL을 사용한 fopen 래퍼를 허용합니다: include, include_once, require, require_once.

Note:

이 설정은 allow_url_fopen이 on이여야 합니다.

user_agent string

PHP가 전송하는 유저 에이전트를 지정합니다.

default_socket_timeout integer

소켓 기반 스트림의 기본 시간 제한(초단위).

Note: 이 설정 옵션은 PHP 4.3.0에서 추가되었습니다.

from string

익명 ftp 패스워드(email 주소)를 지정합니다.

auto_detect_line_endings boolean

on일 때, PHP는 fgets()file()으로 읽혀지는 데이터가 줄바꿈 방식으로 유닉스, MS-DOS, 매킨토시 방식 중 어느걸 사용하는지 검사합니다.

이는 PHP가 매킨토시 시스템과 작업을 할 수 있게 하지만, 첫째 줄에서 EOL 방식을 검출하기 위해서 아주 작은 성능에 페널티가 존재하고, 유닉스 시스템에서 사람들이 아이템 구분자로 캐리지-리턴을 사용해왔었기에, 하위 호환성이 사라질 수 있는 이유로 인해, 기본값은 Off입니다.

Note: 이 설정 옵션은 PHP 4.3.0에서 추가되었습니다.

add a note add a note

User Contributed Notes 3 notes

up
129
Pistachio
12 years ago
I'm surprised this isn't mentioned in docs here, but to set these values at runtime use "ini_set()". For example:

<?php
ini_set
("auto_detect_line_endings", true);

// Now I can invoke fgets() on files that contain silly \r line endings.
?>
up
-14
traian dot bratucu at gmail dot com
7 years ago
Please note that although you may try to set default_socket_timeout to something over 20s, you may get tricked by the Linux kernel.

The default value of tcp_syn_retries is set to 5, which will effectively timeout any TCP connection after roughly 20s, no matter what limits you set in PHP higher than this.

The value can be altered by root only, like this:

echo 6 > /proc/sys/net/ipv4/tcp_syn_retries

A value of 6, as above, will give you a timeout up to ~45s.
up
-22
Chris
7 years ago
If you want to use auto_detect_line_endings, e.g. to recognize carriage return on a Classic Mac file, you must set it before calling fopen. You can then reset it to its original value. E.g,

$original = ini_get("auto_detect_line_endings");
ini_set("auto_detect_line_endings", true);
$handle = fopen($someFile, "r");
ini_set("auto_detect_line_endings", $original);
while (($line = fgets($handle)) !== false) {
  echo "$line\n"; // etc
}

(Reference: https://bugs.php.net/bug.php?id=63341&edit=2)

Keep in mind also that Mac OS X bash does not handle carriage returns well, so if it seems like your code is not working when testing from the command line, redirect your output to a file and then try looking at that. On my system, doing it directly on the command line only showed the last line (with or without this setting turned on).

Also note that this will not do what you want if you have a file with mixed line endings (!). If you really care about that case, you have to do something else, like run the file through a translation first and then read it.
To Top