'php include'에 해당되는 글 2건

  1. 2007.09.18 php 에서 파일 읽기 퍼포먼스 bench.
  2. 2007.08.22 PHP include vs require

php 에서 파일 읽기 퍼포먼스 bench.

ITWeb/개발일반 2007.09.18 11:10

Function

Time (s)

Memory (b)

 

32Kb File

1Mb File

32Kb File

1Mb File

file_get_contents

0.00152

0.00564

52480

1067856

fpassthru

0.00117

0.00184

20016

20032

fgets

0.00195

0.07190

30760

30768

file

0.00157

0.06464

87344

2185624

require_once

0.00225

0.08065

67992

2067696

include

0.00222

0.08202

67928

2067624

readfile

0.00117

0.00191

19192

19208


ref. : http://www.raditha.com/wiki/Readfile_vs_include


신고
크리에이티브 커먼즈 라이선스
Creative Commons License
Trackback 0 : Comment 0

PHP include vs require

ITWeb/개발일반 2007.08.22 14:44

include

  • include_path 를 먼저 찾는다
  • a.php 내부에 b.php 가 include 되어 있으면 b.php 를 먼저 찾는다.
  • include 실패시 warning 을 내고 script 는 진행이 되지만 require 는 fatal error 를 내고 정지 한다.
  • include 는 변수 scope 을 그대로 유지 한다.
  • function, class, defined 는 global scope 을 갖는다.
include() The include() statement includes and evaluates the specified file.

The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well. Be warned that parse error in included file doesn't cause processing halting in PHP versions prior to PHP 4.3.5. Since this version, it does.

Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in the current working directory.

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

require

  • 실행중인 processing 을 중지 하고 싶을 때 사용한다.
  • 상속을 사용하지 않을 때 사용한다.
  • looping 구조에 어떠한 행동도 하지 않는다.
    • loop 안에서 한번만 발생된다.

require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well.

require() will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect require(). However, if the line on which the require() occurs is not executed, neither will any of the code in the target file be executed. Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once.

require_once

  • 이미 include 되어 있다면 다시 include 하지 않는다.
  • require 와 비슷하다.

include_once

  • 이미 include 되어 있다면 다시 include 하지 않는다.
  • include 와 비슷하다.


reference : http://au.php.net/manual/en/function.include.php

신고
크리에이티브 커먼즈 라이선스
Creative Commons License
Trackback 0 : Comment 0

티스토리 툴바