[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Sending file_get_contents to dev/null

Posted on 2009-05-15
Medium Priority
Last Modified: 2012-05-07
Using PHP I need to access a remote website so it can do something (sort of like a crontab)

This works:
$devNull = file_get_contents('http://www.example.com/update.php');

But it places the contents of the website in a string.  I don't want that, it is a watse of memory.

How can I access the webpage but not collect its output?
Question by:hankknight
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

crash36936 earned 1200 total points
ID: 24398962
I guess you just need to see if the site is up?

You can try this: http://us.php.net/manual/en/function.get-headers.php

More information, without all the extra baggage

Assisted Solution

ycTIN earned 400 total points
ID: 24401094

$target = "http://www.example.com/update.php";
$f = fopen($target, "r");

Open in new window


Assisted Solution

markh789 earned 400 total points
ID: 24409488
Attched is some code, the string $header_data becomes an array, here is what it should contain:
    [0] => HTTP/1.1 200 OK
    [1] => Date: Sat, 29 May 2004 12:28:13 GMT
    [2] => Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
    [4] => ETag: "3f80f-1b6-3e1cb03b"
    [5] => Accept-Ranges: bytes
    [6] => Content-Length: 438
    [7] => Connection: close
    [8] => Content-Type: text/html


    [0] => HTTP/1.1 200 OK
    [Date] => Sat, 29 May 2004 12:28:14 GMT
    [Server] => Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
    [ETag] => "3f80f-1b6-3e1cb03b"
    [Accept-Ranges] => bytes
    [Content-Length] => 438
    [Connection] => close
    [Content-Type] => text/html

You can check $header_data[0] for "200 OK" using strstr http://us.php.net/manual/en/function.strstr.php 

$header_data = get_headers("http://www.example.com/update.php");
if(strstr($header_data[0], "200 OK")) {
 echo ":) - sweet.";
} else {
 echo ":( - fail";

Open in new window


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question