• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

file_get_contents() without "Http" to access external URL [closed]

php


PHP Snippet 1:

<?php

$ctx = stream_context_create(array(
    'http' => array(
        'timeout' => 16.0 // seconds
    )
));

$contents = file_get_contents('http://...', FALSE, $ctx);

// do something with $contents

PHP Snippet 2:

$ ./test
{
  "headers": {
    "Host": "httpbin.org"
  }
}

$ cat test
#!/usr/bin/env php
<?php

die(file_get_contents('http://httpbin.org/headers'));

Related Snippets

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

insert multiple rows in a saveall in cakephp

Xdebug can't connect back to Docker host

advanced custom fields wordpress custom class

PHP: PDO + CSV export not downloading (headers issue?)

Transpose and flatten multiple rows of array data [duplicate]

How to get page number on dompdf PDF when using "view"

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Combine multiple columns into an array as one of the key in a results set

Reducing authentication calls on external API (Laravel 5.6)

how to sort by a custom appended relation to model

Trying to iterate over a mongodb cursor twice - failing

Dropzone: Submit both form data and dropzone at once

How to prevent phpmailer sending embedded image as an attachment on Gmail?

php script to delete files older than 24 hrs, deletes all files

About Contact Privacy policy Terms and conditions