您可以使用 virtual() 以有效且高效的方式實作您自己的分派器/驗證處理程序。
例如,如果您有一堆您希望由 Apache 靜態提供的圖像(畢竟這是它的工作),但具有比 mod_access 允許您執行的更複雜的存取模式(例如使用您的應用程式邏輯的 MySQL 查找),請試試看這個簡單的 Apache 規則
complex access pattern than mod_access allows you to do (say a MySQL lookup with your app logic), try this simple Apache rule
Order Allow,Deny
Allow from env=PHP_ALLOW
然後在您的 PHP 腳本中,在發送任何內容或標頭之前
<?php
$image = "/some/URL/path/test.png";
if (client_may_view_image($image)) {
apache_setenv('PHP_ALLOW', '1');
if (virtual($image))
exit(0);
echo "Ops, failed to fetched granted image $image (hammer your webmaster).\n";
} else
echo "Sorry buddy, you're not allowed in here.\n";
?>
當然,這很 Apache-ish,但是依靠 Apache 而不是 passthru() 和 mime_content_type() 更有效率和統一
hack:它執行路徑查找和管理員期望的驗證/安全性稽核,使用它能提供的最佳靜態服務(想想 'sendfile')
你甚至可以將你的請求與另一個嵌入的腳本鏈接起來,例如在 mod_perl 中。