Using timeouts with file_get_contents in PHP

If you are trying to use file_get_contents for fetching data from url’s, you might sometime need to define a timeout value. While it would seem as there is no obvious way, thanks to this comment on the manual page for file_get_contents, there is a pretty simple way.

// create the context
$arContext['http']['timeout'] = 3;
$context = stream_context_create($arContext);

// Fetch data
$url_data = file_get_contents('http://example.com', 0, $context);

There are other options too which can be seen here – http://www.php.net/manual/en/context.http.php

Advertisement

Port conflict between p5-Mail-SPF-Query and p5-Mail-SPF while installing Maia port in FreeBSD

If you are trying to install Maia or any other port which depends upon p5-Mail-SPF-Query, and your server already has p5-Mail-SPF installed, you will not be allowed to do so as both install files at the same location. You would be receiving errors like:

usr/ports/mail/p5-Mail-SPF-Query

===>  p5-Mail-SPF-Query-1.999.1 conflicts with installed package(s): 
      p5-Mail-SPF-2.007

According to this post at FreeBSD forums, p5-Mail-SPF should be preferred. An easy way to do is to edit the Makefile of the port (in my case it’s Maia) to replace the dependency line. Edit /usr/ports/security/maia/Makefile (replace path based on your port) in your favorite editor and search for

.if defined(WITH_SPFQUERY)
RUN_DEPENDS+=   ${SITE_PERL}/Mail/SPF/Query.pm:${PORTSDIR}/mail/p5-Mail-SPF-Query
.endif

and replace it with

.if defined(WITH_SPFQUERY)
RUN_DEPENDS+=   ${SITE_PERL}/Mail/SPF/Query.pm:${PORTSDIR}/mail/p5-Mail-SPF
.endif

That should be it unless you have some other conflicts in your package.

Amitabh Kant