Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:01:31+00:00 2026-05-18T00:01:31+00:00

I have programmed a proxy.php script (listed below), which would fetch an image specified

  • 0

I have programmed a “proxy.php” script (listed below), which would fetch an image specified in the ?img= parameter and print it to the STDOUT. This is needed for my Flash app to circumvent a missing crossdomain.xml at some sites.

It works, but I have 3 questions please. Also I’m coming to PHP from Perl and still have many gaps in my PHP-knowledge (but I realize, that stream_context_create and fpassthru probably use bucket brigades).

1) In my callback() function, how can I print debugging messages to PHP log? (it is redirected to /var/log/messages at my CentOS machine)

2) Why do I get the error message failed to open stream: Success, do I miss a case in the callback() maybe?

PHP Warning:  fopen() [<a href='function.fopen'>function.fopen</a>]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/proxy.php on line 19
PHP Warning:  fopen(http://i136.odnoklassniki.ru/getImage?photoId=154105499212&amp;photoType=0) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Success in /var/www/html/proxy.php on line 19

3) Because my script is often called with the same image URL as parameter, I would like to extend it so that it saves the fetched file in a dir on the 1st call. And on the 1st and subsequent calls it should serve that cached file to STDOUT. Do you have a suggestion, how to make it in a memory-conserving way? I.e. I don’t want to read the whole file at once with get_file_contents()

<?php

define('MAX_SIZE', 1024 * 1024);

$img = urldecode($_GET['img']);
if (strpos($img, '..') !== FALSE)
        exit('Wrong URL: ' . $img);

$opts = array(
        'http'=>array(
                'method' => 'GET'
        )
);

$ctx = stream_context_create($opts);
stream_context_set_params($ctx, array('notification' => 'callback'));
$fh = fopen($img, 'r', FALSE, $ctx);
if ($fh) {
        fpassthru($fh);
        fclose($fh);
}

function callback($code, $severity, $message, $message_code, $bytes_transferred, $bytes_total) {
        if ($code == STREAM_NOTIFY_PROGRESS && $bytes_transferred > MAX_SIZE)
                exit('File is too big: ' . $bytes_transferred);

        if ($code == STREAM_NOTIFY_FILE_SIZE_IS)
                if ($bytes_total > MAX_SIZE)
                        exit('File is too big: ' . $bytes_total);
                else
                        header('Content-Length: ' . $bytes_total);

        if ($code == STREAM_NOTIFY_MIME_TYPE_IS) {
                if (stripos($message, 'image/gif') !== FALSE ||
                    stripos($message, 'image/png') !== FALSE ||
                    stripos($message, 'image/jpg') !== FALSE ||
                    stripos($message, 'image/jpeg') !== FALSE) {
                        header('Content-Type: ' . $message);
                } else {
                        exit('File is not image: ' . $mime);
                }
        }
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:01:32+00:00Added an answer on May 18, 2026 at 12:01 am
    1. Because:

      sviss@sviss:~$ host i136.odnoklassniki.ru
      Host i136.odnoklassniki.ru not found: 3(NXDOMAIN)
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never programmed a gadget for Vista or Seven, but I would like
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
I have programmed (VS2010 SP1, C#) an application which uses a Microsoft SQL Server
I have a customer mangement system that I have programmed in php and mysql.
then, elif, else statement that I have programmed in a bash script. I know
I have programmed a simple app that every X minutes checks if an image
Im new to php and have programmed in other languages. Im trying to solve
I have programmed a Windows Service in C# which should connect to an SQL-Server
I have programmed a simple hibernate app which isn't updating the table. The following
I have programmed a simple hibernate app which leaves me with errors. The following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.