Good morning.
I'm currently assessing whether I should move to PHP Tools for Visual studio and so am using the 30-day free trial. Previously I have used Linux VMs on local Hyper-V with PHPStorm and XDebug, but getting this working seems very hit-and-miss.
Setting up PHP-for-VS was a breeze, but my application makes heavy use of curl to post data back to itself to infer state and then rebuild current view from that. This worked flawlessly in my previous setup but I cannot get it working here.
My post method is below. I have tried many combinations of the CURLOPT_RESOLVE option which has often helped in similar scenarios. But I get 'failed to connect' message as shown in the attached screenshot. Does anyone have suggestions?
Thank you.
public function do_curl_post($data) {
$domain = $_SERVER['SERVER_NAME'];
$port = $_SERVER['SERVER_PORT'];
$remotePort = $_SERVER['REMOTE_PORT'];
//open connection
$ch = curl_init();
//escape and build safe query
$postdata=http_build_query($data);
$url = 'http://' . $domain . '/index.php';
if (str_contains($domain, "localhost")) {
$resolve = array(sprintf("%s:%d:%s", $domain, $port, "127.0.0.1"));
curl_setopt($ch, CURLOPT_RESOLVE, $resolve);
$url = 'http://' . $domain . ':' . $port . '/index.php';
}
$dataSize = count($data);
//set the url, number of POST vars, POST data
//if ($url = "imgamedev.com/index.php") { $url = "172.29.139.123/index.php"; } // local debugging on vmware VM
curl_setopt($ch, CURLOPT_URL, $url); //"150.214.29.10/index.php"
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, $dataSize);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
// if ($url == "imgamedev.com") {
// $resolve = array(sprintf("%s:%d:%s", $url, 80, "172.29.139.123"));
// curl_setopt($ch, CURLOPT_RESOLVE, $resolve);
// }
// if ($url == "imgame1.cf.ac.uk") {
// $resolve = array(sprintf("%s:%d:%s", $url, 80, "131.251.255.30"));
// curl_setopt($ch, CURLOPT_RESOLVE, $resolve);
// }
//execute post
$error = null;
try {
$result = curl_exec($ch);
if (!$result) {
$error = curl_error($ch);
}
} catch (Exception $e) {
$error = $e->getMessage();
}
//close connection
curl_close($ch);
return $result;
}