[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [PHP] fejlhåndtering af fopen, flock og fwrite



On Fri, 16 Dec 2005 14:10:35 +0100, Peter Makholm wrote:

> Jeg har et stykke kode der ser nogenlunde således ud:
> 
> $fh = fopen($record['sourceurl'],'a') || error_log("Coldn't open " .
> $record['sourceurl']); flock($fh,LOCK_EX) || error_log("Ooops, couldnt
> lock"); foreach($tree['rss'][0]['ch']['channel'][0]['ch']['item'] as
> $itemContent) {
>         $item = "bob";
>         error_log("Writing: \n" . $item);
>         fwrite($fh, $item) || error_log("... no we didn't");
> }
> fclose($fh);
>
Og så lige en lille "fejl" - tror det er en bug i php?
Du kan ikke anvende || til at fange fejl ved åbning af filer, da det
betyder, lige meget om du får lov at åbne filen eller ej, at fopen ikke
returne en ressource, hvorfor alle videre operationer på ressourcen vil
resulterer i en fejlmeddelelse om, at $fh ikke er en ressource. Gør
sådan her i stedet for:
$fh = @fopen('$record['sourceurl'],'a');
if (!$fh)
{
    error_log("Coldn't open test.txt");
}
....

-- 
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-01-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *