Forum

cURL

BSmither
6 February 2014, 07:24
Testing with a very simple PHP script with curl, the URL being 127.0.0.1/test4.php, there is a 500 error. However, when the URL is 127.0.0.1/test4.html, the response is as expected.

Testing with a command-line curl, the response is as expected.

I have narrowed it down to Hiawatha or a wrong Hiawatha setting.

Is there a problem with what I am doing that has a solution?

Hiawatha version: 9.3.1
Operating System: WindowsXPSP3-X32

The PHP script requested from the browser:
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"127.0.0.1/test4.php");
curl_setopt($curl, CURLOPT_PORT , 80);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_exec ($curl);
curl_close ($curl);
?>


This is the script responding to the curl request- test4.php:
<?php   echo time() . " "; var_dump($_POST); // should be an empty array  ?>


Another file for testing text-based responses - test4.html:
var_dump($_POST); Should return exactly this.

The Hiawatha config:
ConnectionsTotal = 150
ConnectionsPerIP = 50
SystemLogfile = /cygdrive/l/Hiawatha/log/system.log
GarbageLogfile = /cygdrive/l/Hiawatha/log/garbage.log
ExploitLogfile = /cygdrive/l/Hiawatha/log/exploit.log
PIDfile = /cygdrive/l/Hiawatha/log/hiawatha.pid
WorkDirectory = /cygdrive/l/Hiawatha/work
Binding {
Port = 80
Interface = 127.0.0.1
MaxRequestSize = 1024
}
Binding {
Port = 443
SSLcertFile = /cygdrive/d/my.pem
}
CGIhandler = /cygdrive/l/PHP/php-cgi.exe:php
FastCGIserver {
FastCGIid = PHP5
ConnectTo = 10.1.10.10:2005
Extension = php
}
UrlToolkit {
ToolkitID = CubeCart5
RequestURI exists Return
Match /favicon.ico$ Return
Match ^(/[^/]+)/(.+)\.html?(\?(.+))$ Rewrite $1/index.php?seo_path=$2&$4
Match ^(/[^/]+)/(.+)\.html?$ Rewrite $1/index.php?seo_path=$2
}
Hostname = 127.0.0.1
WebsiteRoot = /cygdrive/l/WebServer
Alias = /htdocs-CC522:/cygdrive/l/WebServer/htdocs-CC522
Alias = /htdocs-CC514:/cygdrive/l/WebServer/htdocs-CC514
StartFile = index.php
AccessLogfile = /cygdrive/l/Hiawatha/log/access.log
LogFormat = extended
ErrorLogfile = /cygdrive/l/Hiawatha/log/error.log
UseFastCGI = PHP5
UseToolkit = CubeCart5
TimeForCGI = 60


This is how I start Hiawatha - a batch file:
@ECHO OFF
START "PHP FastCGI" /dL:\PHP /min L:\PHP\php-cgi.exe -b 10.1.10.10:2005
"L:\Hiawatha\bin\wigwam.exe" -q -c /cygdrive/l/Hiawatha/config
IF ERRORLEVEL 1 GOTO ERROR
"L:\Hiawatha\bin\hiawatha.exe" -d -c /cygdrive/l/Hiawatha/config
IF ERRORLEVEL 1 GOTO ERROR
GOTO END
:ERROR
PAUSE
:END


This is a bad response from FastCGI:
* About to connect() to 127.0.0.1 port 80 (#5)
* Trying 127.0.0.1...
* Adding handle: conn: 0x1d6f728
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 5 (0x1d6f728) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#5)
> GET /test4.php HTTP/1.1
Host: 127.0.0.1
Accept: */*

< HTTP/1.1 500 Internal Server Error
< Date: Thu, 06 Feb 2014 06:00:40 GMT
* Server Hiawatha v9.3.1 is not blacklisted
< Server: Hiawatha v9.3.1
< Connection: close
< Content-Length: 695
< Content-Type: text/html
<
* Closing connection 5

This is a good response from the command line:
D:\>curl -v 127.0.0.1/test4.php
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Adding handle: conn: 0x528930
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x528930) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET /test4.php HTTP/1.1
> User-Agent: curl/7.34.0
> Host: 127.0.0.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 06 Feb 2014 05:53:42 GMT
* Server Hiawatha v9.3.1 is not blacklisted
< Server: Hiawatha v9.3.1
< Connection: keep-alive
< Transfer-Encoding: chunked
< X-Powered-By: PHP/5.4.17
< Content-type: text/html
<
1391666022 array(0) {
}
* Connection #0 to host 127.0.0.1 left intact
Hugo Leisink
6 February 2014, 08:07
What does the error logfile say?
BSmither
6 February 2014, 15:09
Simply:
127.0.0.1|Wed 05 Feb 2014 23:00:40 -0700|l:\WebServer\test3.php|CGI timeout <- has curl statements
127.0.0.1|Wed 05 Feb 2014 23:00:40 -0700|l:\WebServer\test4.php|CGI timeout
Hugo Leisink
7 February 2014, 08:08
CGI timeout means that the CGI script for some reasons runs longer than the value of TimeForCGI. I have no idea what goes wrong with that PHP script.

The pipesign at the start of the path in the logfile might be a clue for the cause of it all. Are you sure the rewriting is done correctly? You can check this via the wigwam tool.
BSmither
7 February 2014, 17:18
By 'pipesign', do you mean the Windows drive letter I (capital eye), or the symbol the error message generator uses to delineate the error log entry parameters (IP then Date, etc.)?

The curl destination 'test4.html' works, and presumably the rewriting is not in effect because the RequestURI exists.
Hugo Leisink
9 February 2014, 08:14
Ah, it's a capital i and not a pipesign. I have no idea what goes wrong. I think it's not a Hiawatha issue, but some sort of PHP / configuration issue.
This topic has been closed.