這可能也是一種選擇: When (if ever) is eval NOT evil?
,似乎來得更快:
$nTestTiempo0 = microtime(true);
exec('php -l yourfile.php',$arrMsgError,$nCodeError);
$nTestTiempo1 = microtime(true);
echo "\n", '<p>Time in verify file with exec : '.($nTestTiempo1-$nTestTiempo0).' secs.</p>';
//Time in verify file with exec : 0.033198118209839 secs.
$nTestTiempo0 = microtime(true);
ob_start();
var_dump(eval('return true; if(0){?>'.file_get_contents('yourfile.php').'<?php };'));
$arrMsgError = explode("\n",trim(ob_get_contents()));
ob_end_clean();
$nTestTiempo1 = microtime(true);
echo "\n", '<p>Time in verify file with eval : '.($nTestTiempo1-$nTestTiempo0).' secs.</p>';
//Time in verify file with eval : 0.00030803680419922 secs.
$nTestTiempo0 = microtime(true);
@system('php -l yourfile.php',$nCodeError);
$nTestTiempo1 = microtime(true);
echo "\n", '<p>Time in verify file with system : '.($nTestTiempo1-$nTestTiempo0).' secs.</p>';
//Time in verify file with system : 0.032964944839478 secs.
包括文件和捕獲異常:P – 2010-10-05 08:23:18
@Ignacio:萬一未舌狀(儘管我認爲是這樣):用錯誤處理程序將致命錯誤轉換爲異常不起作用,更不用說包含該文件將執行它,而這個模塊不應該這樣做。 – pinkgothic 2010-10-05 08:37:20
絕對是舌尖。正確的方法是告訴編譯器編譯它,然後捕獲異常。 – 2010-10-05 08:39:38