0

I have a website hosted on a Centos 6 machine running Apache. From within said website, I have an HTML form that makes a POST request to a PHP page (running in the same Centos 6 machine), whose job is, to pass on said request to a web service running in a different server via curl.

$.ajax({
    method: "POST",
    url: "register.php",
    data: { name: name, lastname: lastname, sex: sex, bithdate: birthdate,  email: email, cellphone: cellphone, country: country }
})
.always(function( msg ) {
    alert( msg );
});

The PHP intermediate code:

<?php

    //extra line
    set_time_limit(0);

    $data = http_build_query($_POST);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://xxxx:8690/register/user");
    curl_setopt($ch, CURLOPT_POST, 1);        
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //extra lines
    curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds

    //flags
    $result = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);
    echo "Error: ".$curl_error." number: ".$curl_errno;
    echo "Result is: ".$result;
    curl_close($ch);
 ?>

The problem is, when using said intermediate PHP page, the request never reaches the web service. If I make the POST request, directly from the website to web service's URL, it works perfectly, but I don't wish to do this, because I would like to keep the web service's URL private for security reasons.

Any help/ideas would be appreciated.

Ivan
  • 1,265
  • 11
  • 20
  • What's the return value for `curl_exec(#ch);`? I mean you can check if it's successful sending out the request from your php code. – Sky Aug 13 '16 at 09:21
  • I've edited the problem to show a couple of flags I added to the PHP code. Sometimes the JS alert shows: Error: Failed to connect to xxxx port 8690: Connection timed out nro: 7 Result:, and other times it just alerts a blank space. It always returns status 200 on Firebug, though. – Ivan Aug 15 '16 at 03:41
  • See if this works for you : http://stackoverflow.com/questions/9349350/curl-and-ssl-connect-time-out – Sky Aug 15 '16 at 06:09
  • Thanks for the help. In regard to the related question, I am not currently using iptables, I do carry out a NAT through the use of virtual servers in my TP-Link router, but when I execute telnet xxxx 8690, I do get a response from the server, albeit it takes more than 1 second. – Ivan Aug 23 '16 at 00:25
  • I also edited the the PHP code in the question, to match a few extra lines I added to my code, to see if they fixed the problem. – Ivan Aug 23 '16 at 00:33
  • The curl_setopt($ch, CURLOPT_NOSIGNAL, 1); line was taken from an answer I saw, related to the > 1s delay given by Simon East in this question: http://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php. The other 2 lines were from msangel's answer on the same question. – Ivan Aug 23 '16 at 00:44

0 Answers0