Zach Saw's Forum

QuickPHP Mod Documentation
Page 1 of 1

Author:  ZachSaw [ October 1st, 2008, 6:38 pm ]
Post subject:  QuickPHP Mod Documentation

Starting Version 1.4.0, QuickPHP supports using PHP scripts to implement extensions / mods (à la Apache modules such as mod_rewrite, mod_headers etc.).

QuickPHP calls QuickPHP_ReqMod.php (in the same folder as QuickPHP.exe) and passes the following variables to the script each time it processes a request. This enables the mods to modify the variables to implement functions such as mod_rewrite.

If QuickPHP_ReqMod.php file does not exist, QuickPHP simply works as before. This mod feature is for advanced users only.

Note that some of the superglobals listed here are not available in every versions of QuickPHP. For example, $ExtraReplyHeaders is only available from v1.8.0 and above. It is therefore recommended that you always upgrade to the latest version.

Variables available to the script:

$DebugLog - Boolean - R/W - Default = true
This flag set to true allows QuickPHP to save the output from executing QuickPHP_ReqMod.php to QuickPHP_ReqMod_DebugLog.txt (same folder as QuickPHP.exe).
This allows you to output message to the log file via Echo, Print, etc. This also saves warning and error output messages from the PHP engine (e.g. Syntax errors in script).

$DebugLogFileName - String - R/W - Default = "QuickPHP_ReqMod_Log.txt"
Logs will be saved to this file after mods have run. Requires $DebugLog to be enabled.

$RequestURI - String - R/W
Read from this variable to find out the URI being requested by the client.
Set this to any URI you wish to redirect the request to (e.g. for implementing mod_rewrite).

$RequestHeaders - String - R/W
Contains the request headers sent from the client.
The request headers are delimited by '\r\n' (return and line feed characters).
To add an arbitary header, simply append a new line to this variable and terminate it with '\r\n'.
There is no limit to the number of headers you can add.
Hint: Parse this string into an array to conveniently add or remove headers and then reconstruct the string at the end.

$ExtraReplyHeaders - String - R/W
Can be used to send additional headers to the client. QuickPHP grabs this string and appends it to the end of the original reply header before sending it to the client.
The reply headers need to be delimited by '\r\n' (return and line feed characters).
To add an arbitary header, simply append a new line to this variable and terminate it with '\r\n'.
There is no limit to the number of headers you can add.
Hint: You can use this to do cache-control for non-PHP mime types (e.g. no-cache).

$UniqueID - String - R/W
Contains a unique ID for the current request.
If you wish to generate your own UniqueID in place of the default, change this value.

$ModuleSignature - String - R/W
Each module should append to this string to indicate its effects on the server.
e.g. ' mod_bwlimited/1.4' (Note the space before the name of the module).
Naming convention - '[space]<module name>/<version>'

$_QUICKPHP_SCRATCHPAD_<x>, <x> == 0 to 99 - String - R/W
These scratch pads are also accessible from your actual script, so they can be used to pass values from mods.

$DocumentRoot - String - R
Holds the current DocumentRoot folder of this server.

$DefaultDoc - String - R
Holds the filename of the default document of this server.

The following are variables similar to $_SERVER['x'].
Some of these values will be updated to reflect the altered $RequestURI (if it is altered) after the execution of the script.

$GatewayInterface - String - R
$QueryString - String - R
$RedirectStatus - String - R
$RemoteAddr - String - R
$RemotePort - String - R
$RequestMethod - String - R
$ScriptFilename - String - R
$ScriptName - String - R
$ServerAddr - String - R
$ServerName - String - R
$ServerPort - String - R
$ServerProtocol - String - R
$ServerSignature - String - R
$ServerSoftware - String - R
$PhpSelf - String - R

*** R - Read-only. They can be changed in the script but will not affect the way server processes the request.
*** R/W - Read-write. Can be changed and will affect the server.

It is recommended that you only include external PHP files from QuickPHP_ReqMod.php.
For example, for mod_rewrite, you could create a file called mod_rewrite.php, and include that in QuickPHP_ReqMod.php.

The QuickPHP_ReqMod.php file could end up calling several mods. In which case, it becomes a convenient place to enable / disable specific mods.

// Disabled mods. Uncomment to enable.

Mod Writing Conventions:
In order to have all the mods working cohesively, the following superglobals usage conventions need to be adhered to closely.

  • Superglobals are required to be left in a valid state at exit point of a mod.
  • If a mod depends on the result of another mod, it is up to the user to include them in the right order.
  • Always keep in mind that multiple mods can run in one request. Therefore, if you are assigning a string to a superglobal, make sure you use the append operator (e.g. $ExtraReplyHeader .= "Cache-Control: no-cache\r\n").

Getting Started:
Get started with this - it simply prints out all the available variables into QuickPHP_ReqMod_DebugLog.txt. Create the following file and save it as QuickPHP_ReqMod.php (put it in the same folder as QuickPHP.exe). Request a page from QuickPHP (either PHP or HTML) and then look for QuickPHP_ReqMod_DebugLog.txt in QuickPHP.exe's folder.
$DebugLog = true;
Echo $DebugLogFileName."\r\n";
Echo $RequestURI."\r\n";
Echo $DocumentRoot."\r\n";
Echo $DefaultDoc."\r\n";
Echo $GatewayInterface."\r\n";
Echo $RequestHeaders."\r\n";
Echo $QueryString."\r\n";
Echo $RedirectStatus."\r\n";
Echo $RemoteAddr."\r\n";
Echo $RemotePort."\r\n";
Echo $RequestMethod."\r\n";
Echo $ScriptFilename."\r\n";
Echo $ScriptName."\r\n";
Echo $ServerAddr."\r\n";
Echo $ServerName."\r\n";
Echo $ServerPort."\r\n";
Echo $ServerProtocol."\r\n";
Echo $ServerSignature."\r\n";
Echo $ServerSoftware."\r\n";
Echo $UniqueID."\r\n";
Echo $PhpSelf."\r\n";
Echo $ModuleSignature."\r\n";
$ModuleSignature .= " mod_helloworld/0.1";

See some mod examples under the thread titled QuickPHP Mods (contributed by Laffin).

Feel free to post your own mods to share with the community.

Author:  distortednet [ October 3rd, 2008, 10:02 am ]
Post subject:  Re: QuickPHP Mod Documentation

exaclty what i needed to test some stuff for an upcomming project.

is there a donate link anywhere? i havent had time to check. id like to donate a couple bux so you can buy beer, energy drinks, and snacks so you can keep coding into the night! DEVELOP DEVELOP DEVELOP!

Author:  ZachSaw [ October 3rd, 2008, 11:25 am ]
Post subject:  Re: QuickPHP Mod Documentation

LOL. :lol: I'm doing this more as a hobby than anything else.

But if you want to contribute, I'd rather it be in the form of scripts to extend QuickPHP server, or to find out if Xdebug could be used with QuickPHP (if not, what needs to be changed).

Otherwise, you could always purchase a single user license of QuickPHP for Commercial Use at $29.

Author:  Laffin [ December 22nd, 2008, 4:49 pm ]
Post subject:  Re: QuickPHP Mod Documentation

Xdebug does work for me, but I've been twiddling with xdebug configuration not shure which one caused it to work.
What I software I do got
QuickPHP 1.40 (WooHoo, nice its great for projects without apache hoggin everything)
PHP 5.2.8 (I want to develop some web apps with sqlite, so had to get it)
Xdebug v2.0.3 & debugclient-0.9.0.exe (the client is a good visual tool that xdebug is working)
and Dev-PHP2 editor (On source forge).

I just wanted something small and fast development environment. but like i said it took awhile to get xdebug working.

but here is my php.ini section for xdebug

Note: the idekey is very importan. but I think it was the remote_autostart that did the trick (as it was one of the last edit I made), but it took a number of restart. s of QuickPHP to get it all working.... good luck.

Oh, I do have a request for a modification to QuickPHP. That is the ability to append to the QuickPHP Mod log file instead of overwriting it each and every time. This way it will be much simpler to create an apache type log, instead of using fputs or similar routine to make a log file.

Oh, and one more suggestion: FastCGI mod for PHP. this will definatelty help speed wise :)

Thanks again for a wonderful piece of software (No more looking up pages on httpd.conf or .htaccess) its much simpler using php as a general purpose module system.
Excellant work.

Author:  ZachSaw [ December 22nd, 2008, 11:02 pm ]
Post subject:  Re: QuickPHP Mod Documentation

Hey Laffin,

It's great to get an expert using QuickPHP - exactly what it needs to see some community contributions to push it forward. I'm still working on a better web server backend which is highly scalable and multithreaded. Reason to this is that the current web server implementation doesn't do a few things - such as flushing output buffers.

Thanks for the Xdebug usage info - I'll have a play with it when I get some time :)

Again, awesome stuff! ;)

Author:  ZachSaw [ October 18th, 2010, 1:41 pm ]
Post subject:  Re: QuickPHP Mod Documentation

Hi guys,

I know this is long overdue, but I've finally got around to change the debug log to append instead of overwrite in QuickPHP Version 1.6.0.
I've also changed the log file name to QuickPHP_ReqMod_DebugLog.txt.

Author:  j5v [ December 10th, 2015, 8:55 pm ]
Post subject:  Re: QuickPHP Mod Documentation

Correction to the above:
(e.g. $ExtraReplyHeader .= "Cache-Control: no-cache\r\n").

should have an extra 's':
(e.g. $ExtraReplyHeaders .= "Cache-Control: no-cache\r\n").

Page 1 of 1 All times are UTC + 10 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group