Most simple CGI scripts can be run directly from OptiPerl, by loading perl with the script, setting it's environment variables, and feeding it if needed with data from the POST method. This is what OptiPerl does when the option "Servers / Run with server" is disabled. Because environment and the POST data is emulated so well just like a real server, the script will be able to run in most cases. OptiPerl then grabs all it's output and sends it to the web browser. A small exception is when running in an external or secondary browser; OptiPerl takes all the output, saves it to a temporary file and loads the external browser with a file:// url to load the temporary file.

 

However there are some problems with this method:

  • You can not really test CGI's that are used to process data from an HTML page, unless you enter the data it expects in the query editor.
  • You can not run CGI's that do not produce text output.
  • Generally, you cannot really test a complete web site, only parts of it. If your website is an interactive site, creates sessions with cookies, has log-ins, forums, polls, banners etc. you can't really test it.

 

The correct solution for testing: Running with a server

 

When enabling the option Server / Run with server, the following changes occur when running files:

 

  • A real http request is sent to the server (that is running offline at that time), like for example:

http://127.0.0.1/cgi-bin/test.cgi. Before, there was no request from the browser; optiperl just feeded it with output of the script.

 

  • After making the request, just like the real world, the browser waits for the output from the server.

 

  • The "submit" buttons, cookies, all work. If you press the submit button on an html form, the browser takes the data of the form, encodes it and requests the "Action" of the form (usually a cgi-script).

 

  • Invoking the debugger after the submit button has been pressed also works. The browser will keep waiting patiently for the data while debugging.

 

  • Because we are emulating the real world, if you have your entire site offline, you can call http://127.0.0.1/ and test all html pages with the scripts they use.

 

icon_exclaim But for the option "Run with Server" to work, you must also load a server! This can be OptiPerl's internal server or an external server. If a server is not loaded, then the browser will return a "page cannot be displayed" error just like when navigating to a non-existent URL when browsing the internet. If a server is not loaded, the URL http://127.0.0.1/ does not exist.

 

What is 127.0.0.1 or localhost?

 

This is a special IP that on all computers means "loopback". When accessing the special http://127.0.0.1/ or http://localhost/, your computer does a loopback and expects a response from itself. If you happen to have a web server loaded on the same computer, the server will be invoked from the request and it will send the response expected.

 

On windows NT/2000/XP/2003 Server, you can also use http://<name of computer>/. The name of the computer can be found on the Network identification page of the system properties.

 

If you are also connected on a LAN, then the IP assigned to the machine will also work.

 

Top  Previous  Next