Solved

PHP curl request is slow

Posted on 2014-01-10
5
2,908 Views
Last Modified: 2014-01-15
Hi,

I'm using curl to retrieve sections of this page:
http://pastorlbm.com/index_03_newsevents.php

instead of the php include since it's by default disabled on networksolutions.

But it's so slow.

So I was reading on some posts that it could be a DNS issue. I found this script from here:
http://www.jeremyquinton.com/how-to-debug-slow-curl-requests-in-php/

and ran it and here is the output:

Array
(
    [url] => http://www.pastorlbm.com/
    [content_type] => text/html
    [http_code] => 200
    [header_size] => 284
    [request_size] => 56
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.03184
    [namelookup_time] => 0.003974
    [connect_time] => 0.005883
    [pretransfer_time] => 0.005965
    [size_upload] => 0
    [size_download] => 20988
    [speed_download] => 659170
    [speed_upload] => 0
    [download_content_length] => 20988
    [upload_content_length] => 0
    [starttransfer_time] => 0.030919
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [redirect_url] => 
)

Open in new window


So it seems the DNS namelookup doesn't seem to be the issue. What else could be causing this?

Thank you,
Victor
0
Comment
Question by:Victor Kimura
  • 2
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 39772242
It is a very slow page that takes about 14 seconds to load.  Part of that is caused by 5 "404 Not found" responses.  The initial page load is over 8 seconds before the browser can even start getting the rest of the files on the page.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 333 total points
ID: 39773415
With something like this you can often use Firefox YSlow to find many of the reasons a page is slow to load.  You will also need Firebug.

My page load time for http://www.pastorlbm.com/ was sub-second.

My page load time for http://pastorlbm.com/index_03_newsevents.php was painfully slow.  There are a lot of files showing in the HTML, as well as JavaScript calls to external web services.  And the queries for the calendar may be slow, too.

Also, there is the markup... sigh.
http://validator.w3.org/check?uri=http%3A%2F%2Fpastorlbm.com%2Fhome.html&charset=%28detect+automatically%29&doctype=Inline&group=0
0
 

Author Comment

by:Victor Kimura
ID: 39774142
Ok, thanks, @Dave and @Ray. It's strange that the only real difference between those pages are the curl function calls which simply separate the page into sections. So all I'm doing is (instead of using PHP include) I'm using curl function calls to separate the left section, top, and footer sections so I can manage the code easier. But the resulting code I believe is all the same.

It's one of those terrible WYSIWYG from Network Solutions. It's temporary solution for now until I transition to something like Wordpress and some other hosted network provider that uses cPanel which I like.

I'll look at Yslow or G Pagespeed. I forgot to validate and I'm sure there are a lot of errors remaining. (sigh). I'll try and convince my pastor to switch but she said not right now I think. I'll try and clean up the code as best as possible and will report here.

Thank you, fellas!
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 333 total points
ID: 39774698
PHP include() requires access to a disk drive, typically on the same server, so it's likely to be measured in the low milliseconds (7200 RPM means 8.3 ms per rotation, more or less).  In contrast, cURL means a trip to the internet, complete with domain name server lookups, socket connections, protocol handshakes, etc.  So it would be expected to be slower than include().  And a few cURL connections would be expected to be much slower that a few include()s.
0
 

Author Comment

by:Victor Kimura
ID: 39776235
Ok, thanks, Ray! I didn't know that (the differences in performance between include() and curl()).

I read that include shouldn't be used because of security issues and it's better to use curl. I'm using curl right now because include is disabled by the hosting provider Network Solutions.

If I'm simply separating the content sections (i.e. header, footer, left sections) by using include() - that is, if I could use it by my hosting provider - then what would the security risk be and is there a way to mitigate or eliminate the security risk by using include (as opposed to curl)?

Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I wrote this article to explain some important DNS concepts that should be known to avoid some typical configuration errors I often see in forums. I assume that what is described here is the typical behavior of Microsoft DNS client. I don't know …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

809 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