1

Are there any other kinds of fetching remote data in PHP, except for: "cURL" and having "allow_url_fopen" in php.ini set to "On", to be able to stream remote content using "fopen", "fsockopen" or "file_get_contents"?

I'm working on a custom-PHP remote content streamer and I'm looking for any other ways of streaming remote content, if the "cURL" or "allow_url_fopen" is "Off".

2 Answers2

1

What about running system calls? Like passthru() or exec() or system() and calling curl or wget on the command line and capturing the data

Linux Example:

ob_start();
passthru("wget -U 'CustomUserAgent' -q -O - 'http://www.example.com/'");
$output = ob_get_clean();

Windows 7+ Example (through powershell). Taken from here

(new-object System.Net.WebClient).DownloadFile('http://www.example.come','C:\tmp\output.tx‌​t') –

To expand on the windows method, see executing a Powershell script from php

Community
  • 1
  • 1
Anthony Hatzopoulos
  • 10,437
  • 2
  • 40
  • 57
  • this will do good only on UNIX/Linux/MAC Operating Systems, and if Windows has installed CygWin or something similar what supports "wget". I'll use this as an fail-safe exception if cURL or "allow_url_fopen" are not available. Thanks mate! +1 & accepted! –  Oct 17 '12 at 01:10
  • 1
    @Zlatan you could possibly achieve it on Windows 7 and above through powershell. I've updated my answer and included some of that info. – Anthony Hatzopoulos Oct 17 '12 at 01:36
1

"allow_url_fopen" does not affect "fsockopen".

Even if it did, having system calls enabled in a webserver is a security threat bigger than having "allow_url_fopen=On".

To disable fsockopen, it can be added to "disable_functions" in php.ini

RibeiroBreno
  • 496
  • 5
  • 12