there is nothing wrong with your code, it works fine here, but there's no error checking anywhere, and you probably get some error somewhere. this should catch your error, try it
<?php
declare(strict_types=1);
error_reporting(E_ALL);
ini_set('display_errors','1');
$url = 'https://wtfismyip.com/text';
$destFile = 'experiment.tmp';
$fp =fopen($destFile, 'w+b');
if (false === $fp) {
throw new RuntimeException ( 'fopen() failed. last error: ' . return_var_dump ( error_get_last () ) );
}
$ch = curl_init();
if (false === $ch) {
throw new RuntimeException ( 'curl_init() failed. last error: ' . return_var_dump ( error_get_last () ) );
}
ecurl_setopt($ch, CURLOPT_URL,$url);
ecurl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
ecurl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
ecurl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
ecurl_setopt($ch, CURLOPT_VERBOSE, true);
ecurl_setopt($ch, CURLOPT_STDERR, $fp);
ecurl_exec($ch);
curl_close($ch);
fclose($fp);
function ecurl_setopt ( /*resource*/$ch , int $option , /*mixed*/ $value ):bool{
$ret=curl_setopt($ch,$option,$value);
if($ret!==true){
//option should be obvious by stack trace
throw new RuntimeException ( 'curl_setopt() failed. curl_errno: ' . return_var_dump ( curl_errno ($ch) ).'. curl_error: '.curl_error($ch) );
}
return true;
}
function ecurl_exec ( /*resource*/$ch)/*:mixed depending on CURLOPT_RETURNTRANSFER*/{
$ret=curl_exec($ch);
if($ret===false){
throw new RuntimeException ( 'curl_exec() failed. curl_errno: ' . return_var_dump ( curl_errno ($ch) ).'. curl_error: '.curl_error($ch) );
}
return $ret;
}
function return_var_dump(/*...*/){
$args = func_get_args ();
ob_start ();
call_user_func_array ( 'var_dump', $args );
return ob_get_clean ();
}