?
Solved

Sending file_get_contents to dev/null

Posted on 2009-05-15
3
Medium Priority
?
384 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 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
0
 
LVL 7

Assisted Solution

by:ycTIN
ycTIN earned 400 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

777 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