• 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 Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

PhP how to calculate moments with variables rows

Execute only one time and then wait set period of time before executing again

Hi, I am making a contact form thingy, and my php isn't working any reason why?

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

How to upload mpdf file after generating to s3 bucket in php

Laravel Excel::store file empty after stored

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)

How to insert Google Adsense Code in PHP script?

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

How to make autocomplete work in foreach php loop? (vscode, intellisense)

Sentry on Symfony: how to exclude `NotFoundHttpException`

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Add New Parameter to Existing URL using htaccess

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

About Contact Privacy policy Terms and conditions