Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Process PHP with TIdHTTPServer
#1
I know how to create a simple web server using TIdHTTPServer and serve .htm files. But what if I wanted to be able to handle .php files like IIS or Apache would? I assume I would need to download the thread-safe Windows binaries for PHP. Then what? A user requests a link with a .php extension. How do I send the .php file contents (with URL parameters) to the PHP processor, wait for it to spit back any output, and send that output back to the user?
Reply
#2
PHP has a CGI gateway. You call it kind of like a command line process and return the results.
Reply
#3
(08-17-2020, 08:45 PM)kbriggs Wrote: How do I send the .php file contents (with URL parameters) to the PHP processor, wait for it to spit back any output, and send that output back to the user?

Per the PHP documentation:

General Installation Considerations

Quote:In case of setting up the server and PHP on your own, you have two choices for the method of connecting PHP to the server. For many servers PHP has a direct module interface (also called SAPI). These servers include Apache, Microsoft Internet Information Server, Netscape and iPlanet servers. Many other servers have support for ISAPI, the Microsoft module interface (OmniHTTPd for example). If PHP has no module support for your web server, you can always use it as a CGI or FastCGI processor. This means you set up your server to use the CGI executable of PHP to process all PHP file requests on the server.

So, you could have your HTTP server access PHP via its (Fast)CGI or ISAPI interface.

Also see:

CGI, ISAPI, and FastCGI

ISAPI Extension Overview

When accessing PHP using CGI, your HTTP server would run php-cgi.exe, redirecting its STDIN and STDOUT/ERR handles, and then send any data received from the client to PHP's STDIN, and send any data received from PHP's STDOUT/ERR back to the client.

When accessing PHP using FastCGI, your HTTP server would connect to a FastCGI processor that is running PHP, then send any data received from the client to the FastCGI processor, and send any data received from the processor back to the client.

When accessing PHP using ISAPI, your HTTP server would load php4isapi.dll and call its exported HttpExtensionProc() function with information about the client connection, request data, etc.

Oh wait, ISAPI support was dropped in PHP 5.3.x  Angry So your only option is now CGI or FastCGI. Unless you want to try your hand at simulating the environments needed to execute PHP's Apache/IIS modules instead.

UPDATE: Or, you can try to compile the core PHP library (or a 3rd party implementation) directly into your app.

Reply
#4
Thanks, I think I have enough info to get started.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)