Using PUT method with PHP cUrl Library

后端 未结 3 2014
温柔的废话
温柔的废话 2020-12-13 04:25

I\'m able to run the following curl command (at the command line) successfully:

curl -XPOST --basic -u user:password -H accept:application/json -H Content-ty         


        
3条回答
  •  情话喂你
    2020-12-13 05:02

    Instead of creating a temp file on disk you can use php://temp.

    $body = 'the RAW data string I want to send';
    
    /** use a max of 256KB of RAM before going to disk */
    $fp = fopen('php://temp/maxmemory:256000', 'w');
    
    if (!$fp) 
    {
        die('could not open temp memory data');
    }
    
    fwrite($fp, $body);
    fseek($fp, 0); 
    
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_INFILE, $fp); // file pointer
    curl_setopt($ch, CURLOPT_INFILESIZE, strlen($body));                            
    

    The upside is no disk IO so it should be faster and less load on your server.

提交回复
热议问题