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 6939699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:39:20+00:00 2026-05-27T12:39:20+00:00

I have Server A and Server B which exchanges some data. Server A on

  • 0

I have Server A and Server B which exchanges some data. Server A on user request pull data from Server B using simple file_get_content with some params, so server B can do all task(database etc) and return results to A which formats and show to user. Everything is in PHP.

Now I am interested what is fastest way to to this? I made some test and average transfer time for average response from server B at (~0.2 sec). In that 0.2 sec, 0.1 sec. aprox. is Server B operational time (pulling data calling few databases etc) what mean that average transfer time for 50kb with is 0.1 sec. (servers are NOT in same network)

Should I try with:

  1. cURL insted of file_get_content ?
  2. Or to try to make whole thing with sockets( I never work work with sockets in PHP but I supose that easily can be done, on that way to skip web server )
  3. or something third?

I think that time can be ‘found’ on shortening connection establishing, since now, every request is new connection initiating (I mean on separate file_get_content calls, or I am wrong?)

Please give me your advices in which directions to try, or if you have some better solution I am listening.

  • 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-27T12:39:20+00:00Added an answer on May 27, 2026 at 12:39 pm

    Curl:

    function curl($url)
    {
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL,$url);
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec ($ch);
        curl_close($ch);
        return $result;
    }
    

    Sockets:

    function sockets($host) {
    $fp = fsockopen("www.".$host, 80, $errno, $errstr, 30);
      $out = "GET / HTTP/1.1\r\n";
      $out .= "Host: www.".$host."\r\n";
      $out .= "Connection: Close\r\n\r\n";
      fwrite($fp, $out);
      $f='';
      while (!feof($fp)) {
        $f .= fgets($fp, 1024);
      }
    return $f;
    }
    

    file_get_contents

     function fgc($url){
           return file_get_contents($url);
        }
    

    Multicurl

    function multiRequest($data,$nobody=false,$options = array(), $oneoptions = array())
    {
        $curls = array();
        $result = array();
        $mh = curl_multi_init();
        foreach ($data as $id => $d)
        {
            $curls[$id] = curl_init();
            $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
            curl_setopt($curls[$id], CURLOPT_URL,            $url);
            curl_setopt($curls[$id], CURLOPT_HEADER,         0);
            curl_setopt($curls[$id], CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curls[$id], CURLOPT_FOLLOWLOCATION,1);
            curl_setopt($curls[$id], CURLOPT_USERAGENT,"Mozilla/5.0(Windows;U;WindowsNT5.1;ru;rv:1.9.0.4)Gecko/2008102920AdCentriaIM/1.7Firefox/3.0.4");
            //curl_setopt($curls[$id], CURLOPT_COOKIEJAR,'cookies.txt');
            //curl_setopt($curls[$id], CURLOPT_COOKIEFILE,'cookies.txt');
            //curl_setopt($curls[$id], CURLOPT_NOBODY, $nobody);
    
            if (!empty($options))
            {
                curl_setopt_array($curls[$id], $options);
            }
            if (!empty($oneoptions[$id]))
            {
                curl_setopt_array($curls[$id], $oneoptions[$id]);
            }
            if (is_array($d))
            {
                if (!empty($d['post']))
                {
    
                    curl_setopt($curls[$id], CURLOPT_POST,       1);
                    curl_setopt($curls[$id], CURLOPT_POSTFIELDS, $d['post']);
                }
            }
            curl_multi_add_handle($mh, $curls[$id]);
        }
        $running = null;
        do
        {
            curl_multi_exec($mh, $running);
        }
        while($running > 0);
        foreach($curls as $id => $content)
        {
            $result[$id] = curl_multi_getcontent($content);
            //echo curl_multi_getcontent($content);
            curl_multi_remove_handle($mh, $content);
        }
        curl_multi_close($mh);
        return $result;
    }
    

    Tests:

    $url = 'example.com';
    $start = microtime(1);
    for($i=0;$i<100;$i++)
    curl($url);
    $end = microtime(1);
    echo "Curl:".($end-$start)."\n";
    
    $start = microtime(1);
    for($i=0;$i<100;$i++)
    fgc("http://$url/");
    $end = microtime(1);
    echo "file_get_contents:".($end-$start)."\n";
    
    $start = microtime(1);
    for($i=0;$i<100;$i++)
    sockets($url);
    $end = microtime(1);
    echo "Sockets:".($end-$start)."\n";
    
    $start = microtime(1);
    for($i=0;$i<100;$i++)
    $arr[]=$url;
    multiRequest($arr);
    $end = microtime(1);
    echo "MultiCurl:".($end-$start)."\n";
    ?>
    

    Results:

    • Curl: 5.39667105675
      file_get_contents: 7.99799394608
      Sockets:
      2.99629592896
      MultiCurl: 0.736907958984
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have client server based app which saves user related data into a zip
We have a reporting server which has a bunch of reports and some ad
we have this scenario: A server which contains needed data and client component which
I have a very simple Java application which downloads a set of foreign exchanges
I have a web application in Java which does data exchange using XML. I
I have developed one application which used to send/receive mails using Exchange Server 2003
I have an HTTP server which is in our internal network and accessible only
I have a web server which saves cache files and keeps them for 7
I have an x64 server which, since my libraries are compiled to AnyCPU, run
I have a web server which is protected behind http-basic-auth. I've read through the

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.