php curl_exec() method reports Error 500 on Alibaba Cloud

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IvanH
    New Member
    • Nov 2017
    • 51

    #1

    php curl_exec() method reports Error 500 on Alibaba Cloud

    Recently when I worked on the feature of scanning a QR code to make a Tmall payment, the curl_exec function always gave an Error 500 report after I coded an order on WeChat and then initiated a request to WeChat using curl, with no other error details provided. I tested the feature locally on Alibaba Cloud servers and it worked fine. But now the customer wanted to move the program on Alibaba Cloud web hosting, and this problem keeps emerging. I have confirmed that curl is on and available, and I have set display_errors and error_reporting to “Display all errors”. However:
    1. Other than “Error 500”, no error details are shown.
    2. Only the access logs are visible for the host, with no error logs available. The php.ini settings and apache settings are also not visible or changeable.
    3. I cannot skip this error using @ or try catch, and curl resource parameters are not correct (I printed every single parameter).
    To sum up, I still cannot locate this error and am anticipating some guidance from other programmers.
    Code:
            $ch = curl_init();
            //Setting timed out
            curl_setopt($ch, CURLOPT_TIMEOUT, $second);
    
            //Set a proxy here if applicable
            if(WxPayConfig::getValue('curl_proxy_host') != "0.0.0.0" 
                && WxPayConfig::getValue('curl_proxy_port') != 0){
                curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::getValue('curl_proxy_host'));
                curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::getValue('curl_proxy_port'));
            }
            curl_setopt($ch,CURLOPT_URL, $url);
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//Perform a strict verification
            //Set the header
            curl_setopt($ch, CURLOPT_HEADER, FALSE);
            //The result must be a string and be output to the screen
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        
            if($useCert == true){
                //Set the certificate
                //Use the certificate: cert and key belong to two .pem files separately.
                curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
                curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::getValue('sslcert_path'));
                curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
                curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::getValue('sslkey_path'));
            }
            //Post submission
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
            //Run the curl
            $data = curl_exec($ch);
            //Return the result
            if($data){
                curl_close($ch);
                return $data;
            } else { 
                $error = curl_errno($ch);
                curl_close($ch);
                throw new WxPayException("Curl error. Error code: $error");
            }
    Last edited by gits; Apr 26 '18, 09:17 AM. Reason: added code tags
  • Andrea1701
    New Member
    • Nov 2017
    • 34

    #2
    In general, web hosting allows you to view the error log, but only the last several logs.
    I guess that this is because of limited memory size. You can open a ticket for inquiry.

    Comment

    Working...