|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-11-21 20:32 UTC] scott at aubrey dot org dot uk
Description:
------------
When building a phar, you can use a default stub creator by using
Phar::createDefaultStub. The first param should run from the CLI, the second from
a web server.
When using the built in CLI-web server and navigating to the phar, the file in
the first param is run. When testing on apache the same file, it runs the second
param.
Test script:
---------------
<?php
$testPhar = new Phar('test.phar',null, 'test');
$testPhar->addFromString('cli.php', '<?php print "CLI".PHP_EOL;exit;');
$testPhar->addFromString('web.php', '<?php print "web".PHP_EOL;exit;');
$testPhar->setStub($testPhar->createDefaultStub('cli.php','web.php'));
Expected result:
----------------
browser should simple output "web"
Actual result:
--------------
browser shows "CLI" when run from CLI web server
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 18:00:01 2025 UTC |
Hi, scott: 1. How can you run .phar file in builtin web server? The server seems can only serve .php file as script file. do you mean rename the .phar file to php ? 2. After rename the phar file to php doesn't reproduce the wrong error output. Could you please post more details about the bug ? thx :)Hi, scott: I got your idea, you use phar file as router script. by look into the builtin server. the route script is a simple script executed before server decide whether to server the php page or not. so In my opinion, the router file is **INDEED** run in cli mode instead of web mode. so the behavior is expected ;-) So I think this bug can change to Not Bug, what do you think?It seems to me, in this case you don't want to use test.phar as router script. You only want to be able to execute test.phar when requested from the web server. For Apache you'd have to configure the respective handler, for the built-in web server you'd have to use a router script, maybe something like the following: <?php $ext = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION); if ($ext == 'phar') { include $_SERVER['SCRIPT_NAME']; return true; } else { return false; } ?> Then the built-in web server should behave as expected.