Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: fileparse(): need a valid pathname

by sundialsvc4 (Abbot)
on Jul 09, 2018 at 20:21 UTC ( #1218190=note: print w/replies, xml ) Need Help??


in reply to Re^2: fileparse(): need a valid pathname
in thread fileparse(): need a valid pathname

Here is an excerpt of an actual trampoline shell-script which runs thousands of times per second today, yes, driving a very old PHP site:   (classic CGI)

#!/bin/sh # This file must be executable by any user and should NOT have # the 'setuid' bit turned on. # Apache must be able to execute it but not modfy it. if [ -z $REQUEST_METHOD ]; then echo "Your vain attempt to run this command outside of Apache fail +s to impress anyone ..." exit fi # Careful, no spaces here ... export PRODUCTION_CLOUD_TEST_DEV_LOCAL=PROD if [ -f "/test-box" ]; then export PRODUCTION_CLOUD_TEST_DEV_LOCAL=TEST elif [ -f "/dev-box" ]; then export PRODUCTION_CLOUD_TEST_DEV_LOCAL=DEV fi # The dot-com suffix becomes "local" on a development box. export DOT_COM_SUFFIX=com if [ -f "/test-box" ]; then export DOT_COM_SUFFIX=test elif [ -f "/dev-box" ]; then export DOT_COM_SUFFIX=dev fi # You might need to modify this export SCRIPT_FILENAME=$PATH_TRANSLATED # The 'exec' command will replace ourselves with the PHP executable. exec /usr/bin/php-cgi --php-ini /iapp/sys/config/php.ini \ $PATH_TRANSLATED

Notice that the trampoline invokes whatever PHP-script the URL originally requested.   It “inserts itself” in front of every request.   Within such a trampoline you can easily (re-)define environment variables to create the environment that the legacy application expects.   When the exec command executes, it replaces the trampoline with the legacy application as though the trampoline had never been involved.

Depending on your exact server configuration, some amount of Apache tomfoolery may be required in order to coax it into running the CGI script correctly for all requests. In our case:

AddType text/html .php AddHandler webapp-php .php # This is the script-alias that must be used with the Actions. Equate + it to the physical directory which must be # described by the "<Directory>" directive just below. ScriptAlias /frobozz-cgi/ /sys/cgi-php/ # Direct each handler to the corresponding trampoline. # We must use the "Alias" here. # "Virtual" is important, too ... just don't ask me why. ;-) Action webapp-php /frobozz-cgi/webapp-php.cgi virtual # Specify access to the physical directory that is referred-to by the +ScriptAlias. <Directory "/sys/cgi-php/"> AllowOverride none Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all granted </Directory>

All of this translates quite-directly to the Perl environment and can be used even when FastCGI technology is being used.   (I do not think that it would apply readily to mod_XXX but I may be wrong.)

The application in question consists of more than five thousand source-files and is about eleven years old.   It is stuffed with environmental dependencies dating back over multiple releases of Apache and of PHP.   Trying to “clean up” all those references would have been profoundly risky.   Instead, we avoided it with a trampoline.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1218190]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2019-12-11 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?