PHP curl put 500错误 [英] PHP curl put 500 error

查看:316
本文介绍了PHP curl put 500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个curl put请求,在我的本地主机上正常工作,但在活的服务器上,它抛出一个500错误。这是我的代码:

  public static function send($ xml)
{
$ xml = str_replace (\\\
,,$ xml);

//写入临时文件
$ put_data = tmpfile();
fwrite($ put_data,$ xml);
fseek($ put_data,0);

$ options = array(
CURLOPT_URL =>'http:// ***************** / cgi-bin / commctrl)。 pl'SessionId ='。Xml_helper :: generate_session_id()。& SystemId = live',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array('Content- type:text / xml' ),
CURLOPT_PUT => TRUE,
CURLOPT_INFILE => $ put_data,
CURLOPT_INFILESIZE => strlen($ xml)
);

$ curl = curl_init();
curl_setopt_array($ curl,$ options);
$ result = curl_exec($ curl);
curl_close($ curl);

return $ result;
}



我在服务器上启用了curl!



有没有人有什么想法为什么它不工作在服务器上?



我还在文件顶部启用了错误报告,但在curl完成后没有错误显示。

感谢



更新:



我已经与客户联系,他们已经确认发送的信息被他们接收并插入他们的后台系统。所以它必须是与作为原因的反应有关。



另一个更新



我试过了一个小块的xml。



其他更新



我认为我可能找到了问题的路径。该脚本似乎超时,因为FastCGI的超时,并且因为我在共享主机,我不能改变它。可以任何人确认吗?



最后更新



我与我的托管服务提供商联系,由于服务器上的超时值,脚本超时,因此无法使用任何PHP函数或ini_set()访问该脚本。

解决方案

如果错误是,像你认为的,与脚本超时做,你没有访问php.ini文件 - 有一个容易修复



只需使用 set_time_limit(INT)其中INT是在脚本开头覆盖php.ini文件中的设置的秒数



设置 set_time_limit(128)的超时应该可以解决所有问题,一般被认为是合理的上限



更多信息,请点击这里 http:// php .net / manual / en / function.set-time-limit.php


I have a curl put request that works fine on my localhost but on the live server it throws back a 500 error. Here is my code:

public static function send( $xml )
{
    $xml = str_replace( "\n", "", $xml );

    //Write to temporary file
    $put_data = tmpfile();
    fwrite( $put_data, $xml );  
    fseek( $put_data, 0 );

    $options = array(
            CURLOPT_URL => 'http://*****************/cgi-bin/commctrl.pl?SessionId=' . Xml_helper::generate_session_id() . '&SystemId=live',
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_HTTPHEADER => array( 'Content-type: text/xml' ),
            CURLOPT_PUT => TRUE,
                CURLOPT_INFILE => $put_data,
            CURLOPT_INFILESIZE => strlen( $xml )
        );

        $curl = curl_init();
        curl_setopt_array( $curl, $options );
        $result = curl_exec( $curl );
        curl_close( $curl );

        return $result;
    }

I do have curl enabled on the server!

Does anyone have any ideas why it is not working on the server? I am on shared hosting if that helps.

I also have enabled error reporting at the top of the file but no errors show after the curl has completed. I just get the generic 500 error page.

Thanks

UPDATE:

I have been in contact with the client and they have confirmed that the information that is sent is received by them and inserted into their back office system. So it must be something to do with the response that is the cause. It is a small block of xml that is suppose to be returned.

ANOTHER UPDATE

I have tried the same script on a different server and heroku and I still get the same result.

ANOTHER UPDATE

I think I may have found the route of the issue. The script seems to be timing out because of a timeout on FastCGI and because I am on shared hosting I can not change it. Can any one confirm this?

FINAL UPDATE

I got in contact with my hosting provider and they confirmed that the script was timing out due to the timeout value on the server not the one I can access with any PHP function or ini_set().

解决方案

If the error is, like you think it is, to do with a script timeout and you do not have access to the php.ini file - there is an easy fix

simply use set_time_limit(INT) where INT is the number of seconds, at the beginning of your script to override the settings in the php.ini file

Setting a timeout of set_time_limit(128) should solve all your problems and is generally accepted as a reasonable upper limit

More info can be found here http://php.net/manual/en/function.set-time-limit.php

这篇关于PHP curl put 500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆