Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

POST requests for script are taking 3 minutes

Discussion in 'General Discussion' started by Vinicius Aquino, Dec 4, 2018.

  1. Vinicius Aquino

    Vinicius Aquino Registered

    Joined:
    Dec 4, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brazil
    cPanel Access Level:
    Root Administrator
    All my POST-type requests for a specific URL are taking about 3 minutes to return the response, that is, a few seconds after I submit the form, I look at the API site and there are my data posted, but on my site the request is pending, after exactly 3 minutes it is finished returning the necessary data.

    I think something is holding the response for 3 minutes because I tested the same code in the local environment and it worked quickly (it took about 10 seconds), what could be causing this "slowness"?

    i.stack.imgur.com/XFRmp.png
     
    #1 Vinicius Aquino, Dec 4, 2018
    Last edited by a moderator: Dec 4, 2018
  2. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,893
    Likes Received:
    152
    Trophy Points:
    343
    cPanel Access Level:
    Root Administrator
    Really don't have enough information here.

    This is going to depend on what the script you are posting to is doing before it returns something.

    This would have to be diagnosed from the developers side.
     
  3. Vinicius Aquino

    Vinicius Aquino Registered

    Joined:
    Dec 4, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brazil
    cPanel Access Level:
    Root Administrator
    I am the developer, the script is in PHP:

    URL: api.binance.com/api/

    PHP:
        private function privateRequest($url$params = [], $method 'GET')
        {
            
    $params['timestamp'] = number_format((microtime(true) * 1000), 0'.''');
            
    $params['recvWindow'] = $this->recvWindow;

            
    $query http_build_query($params'''&');

            
    $sign hash_hmac('sha256'$query$this->secret);

            
    $headers = array(
                
    'X-MBX-APIKEY: ' $this->key,
            );

            
    curl_setopt($this->curlCURLOPT_HTTPHEADER$headers);
            
    curl_setopt($this->curlCURLOPT_URL$this->url $url "?{$query}&signature={$sign}");

            
    curl_setopt($this->curlCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($this->curlCURLOPT_FOLLOWLOCATION1);
            
    curl_setopt($this->curlCURLOPT_HTTP_VERSIONCURL_HTTP_VERSION_1_1);
            
    curl_setopt($this->curlCURLOPT_ENCODING'');

            if (
    $method == "POST") {
                
    curl_setopt($this->curlCURLOPT_POST1);
                
    curl_setopt($this->curlCURLOPT_POSTFIELDS, array());
            }

            if(
    $method == 'GET'){
                
    curl_setopt($this->curlCURLOPT_POSTfalse);
            }

            if (
    $method == 'DELETE') {
                
    curl_setopt($this->curlCURLOPT_CUSTOMREQUEST$method);
            }


            
    //Get result
            
    $result curl_exec($this->curl);


            if (
    $result === false) {
                throw new \
    Exception('CURL error: ' curl_error($this->curl));
            }

            
    // decode results
            
    $result json_decode($resulttrue);
            if (!
    is_array($result) || json_last_error()) {
                throw new \
    Exception('JSON decode Error');
            }

            return 
    $result;
        }
     
    #3 Vinicius Aquino, Dec 4, 2018
    Last edited by a moderator: Dec 4, 2018
  4. WorkinOnIt

    WorkinOnIt Well-Known Member

    Joined:
    Aug 3, 2016
    Messages:
    161
    Likes Received:
    13
    Trophy Points:
    18
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Check server logs, also in Chrome developers, you should be able to get network diagnosis to see what exactly is hanging and where. Then look at the script and output to a log to show progress at key points to help narrow down where the bottle neck is occurring or what part of the script is failing.
     
  5. Vinicius Aquino

    Vinicius Aquino Registered

    Joined:
    Dec 4, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brazil
    cPanel Access Level:
    Root Administrator
    The script works very well on my localhost and on another server, I honestly do not know how to find the problem, I've been struggling for more than 10 hours to solve this. What logs do you tell me to check for in the WHM or Cpanel panel?
     
  6. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,893
    Likes Received:
    152
    Trophy Points:
    343
    cPanel Access Level:
    Root Administrator
    You'll just have to figure out where the script is being held up. There's not really a golden goose that tells you how to do that.

    What URL are you posting to? Is that server responding accordingly?
     
  7. WorkinOnIt

    WorkinOnIt Well-Known Member

    Joined:
    Aug 3, 2016
    Messages:
    161
    Likes Received:
    13
    Trophy Points:
    18
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    If works on local host and other server, then could be something e.g. firewall or other blockage. Check error logs in cpanel and whm, if you use CSF disable it temporarily etc... double check settings in your script config - if you moved from localhost, make sure you've connected it properly - triple check if you're tired (10 hrs on it, seems a long time!) good luck.
     
  8. Vinicius Aquino

    Vinicius Aquino Registered

    Joined:
    Dec 4, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brazil
    cPanel Access Level:
    Root Administrator
    The problem was in my script, a function that called the API before the main request and was being blocked.
     
  9. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    5,815
    Likes Received:
    443
    Trophy Points:
    233
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @Vinicius Aquino


    I'm glad to see you were able to identify the cause of the issue! Thanks for updating us here as well.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice