Ne, PHP ilk olur içermesi veya ayrıştırma?

3 Cevap php

Hiçbir bayt önbelleği varsayalım.

my_func a & önce işlenecek b dahil veya sonra olan?

$x=my_func();

//a.php and b.php are **very** heavy scripts
include ('a.php');
include ('b.php');


//my_func makes the browser use it's cached version of the page.
function my_func(){
  //send caching headers
  //header(....);
  exit;
}

3 Cevap

Neden denemiyorsunuz?

: Örneğin, temp.php, bu içeren adında ilk dosya olabilir

<?php

$a = my_func();

include 'temp-2.php';

function my_func() {
    die;
}

Ve ikinci dosya, temp-2.php, bu içerecektir:

<?php

sleep(5);

Eğer temp.php web tarayıcıdan çağırdığınızda sayfa yüklemek için, ne kadar sürer? Bu neredeyse anlık? Ya da 5 saniye sürer?

temp-2.php eklenmeden önce ilk durumda, fonksiyon denir.

... Ve, denedikten sonra: o sadece bir an sürer - işlevinde bir kalıp veya çıkış olduğunda ikinci dosyayı dahil değildir anlamına gelir.


EDIT after the comment : oh, üzgünüm, ben gerçekten soruyu anlamadı, herhalde :-(

temp.php hala bu içerir: İşte başka bir deneyin:

<?php

$a = my_func();

include 'temp-2.php';

function my_func() {
    die;
}

Ama temp-2.php dosya şimdi sadece o içerir:

<?php

,

Hangi PHP bu dosyayı ayrıştırmak için çalışırsa, evet, sana bir ayrıştırma hatası alırsınız.


If you call temp.php from your problem, it doesn't seem to be any problem at all : nothing is displayed, and there is no parse error.

Eğer my_func işlevi içinde "die" satır yorum ve tarayıcınızda tekrar temp.php arama deneyin Şimdi, eğer, olsun:

Parse error: syntax error, unexpected ',' in /home/squale/developpement/tests/temp/temp-2.php on line 3

Hangi PHP bu ikinci dosyayı ayrıştırmak için çalışırsa bir ayrıştırma hatası var demektir.


So, the first time, the function has been called before PHP actually tried to parse the second file.

Daha iyi soru bu cevap, bu kez umut :-)

Içerir idam edilmeden önce Evet, my_func çağrılır. Onlar etkili ziyade ayrıştırma zaman daha bir "çalışma süresi" mekanizması, sensin. Hatta akış kontrolü bunları sararak, koşullu içerebilir.

Temelde sipariş doğru olacaktır. Düşünün:

a.php:

<?php echo "A\n"; ?>

b.php:

<?php echo "B\n"; ?>

c.php:

<?php
my_func();

include 'a.php';
include 'b.php';

function my_func() {
  echo "C\n";
}
?>

Çıkış olacaktır:

C
A
B

Ancak c.php değiştirin:

<?php
my_func();

include 'a.php';

function my_func() {
  include 'b.php';
  echo "C\n";
}
?>

ve çıkış değişir:

B
C
A