Page 1 of 1

Need help with converting cgi to php

Posted: Mon Jan 19, 2004 11:58 am
by jminscoe
does anyone know how I can convert from this format http://www.jodeewebhosting.com/ask/index.php to this format http://www.jodee.biz/scgi-bin/rlinks/rlinks.cgi?m=index but keep it as php

Posted: Mon Jan 19, 2004 10:35 pm
by Stoker
your subject says from cgi to php, your message indicates the other way around?

cgi is not comparable to php, cgi is an interface for executing server side executables on the server, php is a script-engine.

normally (most cases) when processing .php files with apache, it uses a built in module, mod_php, to process the file with the php engine.

A cgi script can be any executable, and the webserver simply executes it and returns the output, executable scripts have an intepreter locator in the first line, like #!/path/to/php

So, in cas of converting a cgi to php, it depends.. if it is a php script it should be as simple as removing the first line that references the php intepreter..

Creating a cgi script from a PHP file is very simple, simply add the intepreter reference at the top of the file, rename and make the file executable.

Posted: Mon Jan 19, 2004 11:04 pm
by lazy_yogi
Stoker wrote:cgi is not comparable to php, cgi is an interface for executing server side executables on the server, php is a script-engine.
Haha .. php IS cgi.

Read up on what cgi actually is. It is where a request is sent to the server to be executed and then sends back the result. That is, it's run server-side. Which is php. Which is CGI.


So jminscoe, it works the same, just doesnt need to be run in a different cgi directory like the older languages like perl do.

Posted: Mon Jan 19, 2004 11:11 pm
by timvw
Add this line on top of your phpfile:
#!/path/to/php

To find out where php is, you could do:
which php

Done ;)

Posted: Tue Jan 20, 2004 8:21 am
by Stoker
lazy_yogi wrote:Read up on what cgi actually is.... it's run server-side. Which is php. Which is CGI.
I have read that specification a couple of times, CGI stands for Common Gateway Interface, and specifies what environment variables should be set and how the webserver sends POSTed data to STDIN of a local executable and requires a content header before returning the rest of STDOUT back to the client.
PHP can of course be exeuted through a CGI interface, just as well as any other executable program or script, but PHP is not comparable.. An intepreter vs an Interface/Spec.

Clarification

Posted: Tue Jan 20, 2004 10:18 am
by jminscoe
I think what I should have asked is how can I make my cgi db a php db as I want to keep my link db that is cgi now but convert it to a php one as I don't like the looks of the one that is now php to I just make tables or what?

Posted: Tue Jan 20, 2004 10:36 am
by timvw
That's the nice part of a database.

You can query it with any language that has an interface to that database.

I don't know in what language your blah.cgi script is written, but i suspect it is written in perl. Meaby you need to have a look at Perl DBI ?