note 51843 added to function.fopen
| From: | theo at oracle dot 2question dot com | Date: | Tue, 12 Apr 2005 21:59:07 +0000 |
| Subject: | note 51843 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87912@lists.php.net to get a copy of this message | ||
here a suggestion for a time out when using a url.
in stead of using fopen en fread with pcntl (if compiled within your php), it is easier to use the
curl function available on linux distributions.
example:
function saveURL2Disk($url, $filename) {
// the microtime_float function is defined on the php website
$start=microtime_float();
// the timeout in seconds
$timeout=10;
// a system call to the curl function (see man curl)
$res=system("curl -m $timeout $url > $filename", $retVal);
$end=microtime_float();
$duration=$end-$start;
if ($duration < $timeout)
$filesize=filesize($filename);
else
$filesize=0;
// the returning filesize could be used as an identifier for succesful download
return $filesize;
}
$filesize=saveURL2Disk('http://www.2question.com/index.html',
'/tmp/out.html')
kind regards,
theo theunissen
----
Manual Page -- http://www.php.net/manual/en/function.fopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51843
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51843&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51843&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51843&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51843&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51843&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51843&report=yes
Search -- http://master.php.net/manage/user-notes.php