0

My desktop application is HTTP posting data to my Apache server (interacting with my PHP script). I am posting alot of data (the contents of a file that is 800kb in size).

When I send the HTTP post request it times out with the below Windows error:

ERROR_INTERNET_TIMEOUT The request has timed out

But if I send smaller files then everything is fine and my PHP script handles the post request. What could be the cause of this and how can I fix this?

My website is WordPress and I have changed my php.ini, php5.ini and .user.ini to all have the following text but it still fails for large files.

file_uploads = On
post_max_size = 128M
upload_max_filesize = 128M 

Edit: After inspecting using phpinfo(); (should max_execution_time have an S on the end (for seconds?):

  • max_execution_time 10
  • memory_limit 128M
  • post_max_size 128M
  • upload_max_filesize 128M
  • max_input_nesting_level 64
  • max_input_time 10
  • max_input_vars 1000

C++ code:

TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded");
LPSTR accept[2] = { "*/*", NULL };

HINTERNET hConnect = NULL, hSession = NULL, hRequest = NULL;
DWORD len = postData.length() * 2;
tstring formattedPostData(len, ' ');
InternetCanonicalizeUrl(postData.c_str(), &formattedPostData[0], &len, ICU_BROWSER_MODE);
std::replace(formattedPostData.begin(), formattedPostData.end(), '=', '~');
tstring authData = _T("usage=") + formattedPostData + _T("&auth=") + authToken;

hSession = InternetOpen(_T("uploader"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hSession) {
    output(_T("InternetOpen failed: %s\n"), getLastErrorAsString().c_str());
    res = S_UNDEFINED_ERROR.state;
    goto Cleanup;
}

hConnect = InternetConnect(hSession, domain.c_str(),
    INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (!hConnect) {
    output(_T("InternetConnect failed: %s\n"), getLastErrorAsString().c_str());
    res = S_UNDEFINED_ERROR.state;
    goto Cleanup;
}

hRequest = HttpOpenRequest(hConnect, _T("POST"),
    domainScript.c_str(), NULL, NULL, (LPCWSTR*)&accept, INTERNET_FLAG_NO_CACHE_WRITE, 1);
if (!hRequest) {
    output(_T("HttpOpenRequest failed: %s\n"), getLastErrorAsString().c_str());
    res = S_UNDEFINED_ERROR.state;
    goto Cleanup;
}

// Error occurs here
output(_T("Post: %s\n"), authData.c_str());
if (!HttpSendRequest(hRequest, hdrs, -1, (LPVOID)authData.c_str(), authData.size() * sizeof(TCHAR))) {
    // Error is 12002: timeout
    output(_T("HttpSendRequest failed: %d.\n"), GetLastError());
    res = S_UNDEFINED_ERROR.state;

    char responseText[1024]; 
    DWORD responseTextSize = sizeof(responseText);

    output(_T("Res: %d\n"), HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, &responseText, &responseTextSize, NULL));
    output(_T("Response: %s\n"), responseText);

    goto Cleanup;
}
Merl
  • 121
  • 1
  • 10

1 Answers1

1

Have you tried increasing the script timeout?

http://php.net/manual/en/function.set-time-limit.php

Also are you posting files or chunks of text copy'n'pasted into a textarea or the like?

  • my desktop application is posting the file contents as one long string. For eg; `fileContents=abc....&auth=abc` – Merl Aug 02 '16 at 07:53
  • As a http post or get? Also the string you're sending are there any weird characters in there? – Paul Broomfield Aug 02 '16 at 08:04
  • its a post and it is urlencoded but I also have to replace the files `=` characters with `~` characters to not conflict with post format – Merl Aug 02 '16 at 08:05
  • ok cool - are you using a form to send the data up? have you set the enctype? http://www.w3schools.com/tags/att_form_enctype.asp Have you got an example of some code we could look at. – Paul Broomfield Aug 02 '16 at 08:07
  • also when updating the .ini files did you restart the http server? – Paul Broomfield Aug 02 '16 at 08:10
  • Its a GoDaddy shared server, how would I/can I restart it? – Merl Aug 02 '16 at 08:12
  • hmm not sure - perhaps it will take affect straight away. Create a page with the following in to see if your ini updates are in affect. – Paul Broomfield Aug 02 '16 at 08:15
  • also if you setup a local server do you get the same issue? – Paul Broomfield Aug 02 '16 at 08:16
  • https://au.godaddy.com/help/phpiniuserini-changes-not-taking-effect-5647 – Paul Broomfield Aug 02 '16 at 08:22
  • ok, thanks for doing the phpinfo bits. The max_execution_time and max_input_time are in seconds and dont need an 's' on the end. But they are a little low - try upping them to 30 or 60 and see if that fixes it. – Paul Broomfield Aug 02 '16 at 23:21
  • also have you tried changing the header to multipart/form-data instead? http://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data – Paul Broomfield Aug 02 '16 at 23:52