Solved

Sending file_get_contents to dev/null

Posted on 2009-05-15
3
379 Views
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?
0
Comment
Question by:hankknight
[X]
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
3 Comments
 
LVL 2

Accepted Solution

by:
crash36936 earned 300 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
0
 
LVL 7

Assisted Solution

by:ycTIN
ycTIN earned 100 total points
ID: 24401094

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

Open in new window

0
 
LVL 3

Assisted Solution

by:markh789
markh789 earned 100 total points
ID: 24409488
Attched is some code, the string $header_data becomes an array, here is what it should contain:
Array
(
    [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
)

OR

Array
(
    [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 

<?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

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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