Can file_get_contents() be used on DreamHost?

software development

#1

I read somewhere that file_get_contents() is blocked on most hosts when trying to get an external page. Is this the case on DH, or are we allowed to use it?

Thanks!


#2

here are some wiki references that might help: http://wiki.dreamhost.com/index.php?title=Special%3ASearch&search=file_get_contents()&fulltext=Search


#3

It does work, but use it carefully — it’s inherently slow, as it makes PHP have to wait for the external page to load before it can continue.


#4

Does DH have any kind of limit to how long a PHP script can take to execute?


#5

Scripts that take longer than 30 seconds to start generating output will run the risk of timing out and displaying an error page.

Also keep in mind that a lot of users will assume the site is broken if pages take more than a few seconds to start loading. By the time our servers time out entirely, most of your visitors will have already given up and left!


#6

Thanks for all of your help.

This actually isn’t for site users to see. I’m making a little script that uses file_get_contents() (or cURL, it’s easy to change between the two) to scrape Google search results to find out what my website’s position is in Google for different search terms. It takes about 50 seconds to execute. Is there a way I can extend the PHP timeout value?

Thanks!


#7

If the script doesn’t need to run through the web server, don’t! Run it from the command line, or using a cron job.

Note also that Google specifically prohibits scraping their results. You may be able to get away with a few queries once in a while, but don’t count on it working reliably, especially if you’re checking a lot of terms.


#8

I’m not sure how to run it through command line, but I have looked at the cron job page before and it looks easy to setup. Will the script execution time be a problem if I run it as a cron job?

And I know Google technically doesn’t allow people scraping their results, but I’m only doing it for about 50 keywords once or twice a week. I was manually counting my position before, which was really time consuming (not to mention a total waste of time).


#9

why not just use google’s webmaster tools which tell you your page rank for keywords???