Short Tag – Web Development Blog

Entries Tagged ‘stream context’

Stream Context in PHP (The CURL alternative)

In PHP there are several ways to get the content of a URL.
A well known method is using the function file_get_contents().
Another way would be using the cURL classes. The thing is, cURL may not be available an all hosts and you might be forced to use file_get_contents, or you just want to use file_get_contents() because [...]

file_get_contents() timeout in PHP

Though file_get_contents is not so advanced as CURL we can use it in lots of situations. In case you use file_get_contents and you need to set for how long to try to make connection you can use stream context.
First we create the stream context:
$sc = stream_context_create(array( ‘http’ => array( [...]