How can I download a file using copy through an ntlm proxy on php? : <p>I have a qemu linux virtual machine and I'm trying to install composer on it using the commands on the composer page. I'm on a windows network accessing the internet through a proxy that uses ntlm, so I use cntlm to authenticate linux and other programs on my PC (thanks to the people that created cntlm). I added the context to the copy command needed to access the proxy but it doesn't work.</p>

<p>This are the command used so far:</p>



<pre class="lang-bash prettyprint-override"><code>$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php', stream_context_create(['https' =&gt; ['proxy' =&gt; 'http://10.0.2.2:3128/']]));"

# a variant
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php', stream_context_create(['https' =&gt; ['proxy' =&gt; 'tcp://10.0.2.2:3128/']]));"
</code></pre>

<p>The answer is:</p>

<pre class="lang-bash prettyprint-override"><code>PHP Warning: copy(https://getcomposer.org/installer): failed to open stream: Connection timed out in Command line code on line 1
</code></pre>

<p>Download the file using wget works fine. </p>

<pre class="lang-bash prettyprint-override"><code>$ env | grep "proxy"
https_proxy=http://10.0.2.2:3128/
http_proxy=http://10.0.2.2:3128/
$ wget -O composer-setup.php https://getcomposer.org/installer
--2017-09-XX XX:XX:XX-- https://getcomposer.org/installer
Connecting to 10.0.2.2:3128 ... conected
Request send ... 200 OK
... etc
2017-09-XX XX:XX:XX (XX KB/s) - composer-setup.php saved [305728/305728]
</code></pre>

<p>The sites used as reference:</p>

<ul>
<li><a href="https://getcomposer.org/download/" rel="noreferrer">https://getcomposer.org/download/</a></li>
<li><a href="http://php.net/manual/en/function.copy.php" rel="noreferrer">http://php.net/manual/en/function.copy.php</a></li>
<li><a href="http://php.net/manual/en/function.stream-context-create.php" rel="noreferrer">http://php.net/manual/en/function.stream-context-create.php</a></li>
<li><a href="http://php.net/manual/en/context.http.php" rel="noreferrer">http://php.net/manual/en/context.http.php</a></li>
</ul>

<p>I know there is a manual way to install composer, but I'm just a bit curious, How can make this work?</p>
