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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:05:36+00:00 2026-06-11T09:05:36+00:00

My PHP project works by grabbing data from a WCF REStful web service with

  • 0

My PHP project works by grabbing data from a WCF REStful web service with curl.

However, for some reason the curl_exec function always takes around 100ms to return, even though the WCF web service is on the same machine, and the WCF service function being called only takes 3ms to execute.

I’ve profiled the WCF service and the entire WCF stack accepts a HTTP request and returns the resultant XML (a tiny XML structure with 5 elements) in under 10ms.

Below is my cURL set-up code:

    $curl = curl_init($this->uri);

    curl_setopt($curl, CURLOPT_HEADER        , true ); // return response HTTP headers in output
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true ); // return result instead of echoing
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop cURL from verifying the peer's certificate. This is set because by default (and right now) cURL does not trust /any/ certificate.
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true ); // follow redirects, Location: headers (but does it really?)
    curl_setopt($curl, CURLOPT_MAXREDIRS     , 10   ); // but dont redirect more than 10 times

    curl_setopt($curl, CURLOPT_CUSTOMREQUEST , $this->method );

    if( isset( $this->username  ) )
        curl_setopt($curl, CURLOPT_USERPWD  , $this->username . ':' . $this->password );

    if( isset( $this->userAgent ) )
        curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent);

    if( isset( $this->content ) ) {
        curl_setopt($curl, CURLOPT_POSTFIELDS, $this->content );

        array_push( $this->headers, 'Content-Length: '. $this->contentLength );

        if( isset( $this->contentType ) )
            array_push( $this->headers, 'Content-Type: ' . $this->contentType );
    }

    if( isset( $this->contentFile ) ) {
        curl_setopt($curl, CURLOPT_INFILE    , $this->contentFile   );
        curl_setopt($curl, CURLOPT_INFILESIZE, $this->contentLength );
        array_push( $this->headers, 'Content-Length: '. $this->contentLength );
        array_push( $this->headers, 'Content-Type: '  . $this->contentType );
    }

    if( count( $this->headers ) > 0 )
        curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers );

The call to curl_exec happens immediately after this block of code, and it’s the curl_exec call that I measure at 100ms consistently.

It’s important I get the load times of this PHP site down, and I can’t understand why this happens.

UPDATE:

cURL’s curl_exec always seems to take 100ms regardless of what is being requested, although very interestingly when I make a second curl_exec request (in the same PHP page execution) it completes a lot quicker – around 20ms.

The mystery deepens.

UPDATE 2:

I realised that curl_getinfo() returns an associative-array containing timing information. When I dump the info from the first cURL request I see the following:

'total_time' => 0.125,
'namelookup_time' => 0.125,
'connect_time' => 0.125,
'pretransfer_time' => 0.125,
'starttransfer_time' => 0.125,

Whereas all subsequent requests are like this (or better):

'total_time' => 0.016,
'namelookup_time' => 0,
'connect_time' => 0,
'pretransfer_time' => 0,
'starttransfer_time' => 0.016,

It seems the delay is in namelookup, but I don’t know why DNS lookup takes so long given that Windows (the server OS) already has the DNS information cached and other applications (desktop, ASP.NET, etc) can resolve the name in under 1ms, but cURL does it in 125ms.

What’s so special about cURL that it can’t use the OS’s DNS cache?

  • 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-06-11T09:05:37+00:00Added an answer on June 11, 2026 at 9:05 am

    I think it’s a bug in the version of cURL included in my PHP installation. After I updated cURL (and PHP) to a more recent version the problem disappeared and curl_exec executes in under 20ms now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made some CMS in PHP which manipulates with data from MySQL. In my
In a PHP project I have some data I want to sort using a
I develop some PHP project on Linux platform. Are there any disadvantages of putting
I use smarty template language in my php project. It works great except I'm
I currently have a NetBeans php project setup to sync from my user directory
I'm currently migrating my project from PHP (codeigniter) to Rails3 and it's amazing. But
I'm having a problem with my PHP pagination for a project. It almost works
I'm from a PHP background but have been given a Django project to administer,
I have developed a PHP webshop project which works independently for each customer. Meaning
I have successfully installed FOSUserBundle in my project and everything works as expected. However,

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.