Search code examples
phpwindows-server-2016iis-10

PHP file_get_contents sends to same port when changed with about 1 minute


I have a PHP script that calls our server running IIS 10 on different specified ports. It is PHP version 7.3.12. I am running this script from a shelled out windows process by doing "php.exe script.php", not from a browser request. When I change ports within about a minute, it is keeps sending to the first port specified.

As an example, if I run the script 3 times doing these 3 iterations in a row:

$result = file_get_contents('https://example.com:6447/token', false, $context);
$result = file_get_contents('https://example.com:6453/token', false, $context);
$result = file_get_contents('https://example.com:6447/token', false, $context);

and check the logs, they all are logged under 6447.

I tried the exact same thing with postman and it works as expected. the first and third ones log under 6447 and the second under 6453.

I then tried copying the script and running them separately and it still posts to the wrong port.

Is there something I need to do to close the connection or something. I am stumped.


Solution

  • Ok, we solved it. Here are the notes:

    • The scripts were calling the DNS FQDN “example.com”. Inside “Domain Controller” DNS translated it to “xxx.xxx.100.10”
    • xxx.xxx.100.10 is on the Citrix Netscaler. Intended during development to funnel requests to the IIS Server IP address and mitigate the attack surface until Windows Firewall settings were done.
    • The setting was left because no issues were occurring at the time.
    • The Netscaler was doing too good of a job by holding the source record & port constant even if a new port came from the same source “too soon”
    • Changing the Internal DNS record to point “example.com” to IIS Server IP Address made the requests go direct, eliminating the issue

    Thank you to Barmar for working through this with me and pointing me in the right direction.