[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
 

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



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);

Hvis filen ikke findes bliver den oprettet, forbliver tom og der
kommer følgende ud i loggen:

[Fri Dec 16 13:45:11 2005] [error] Ooops, couldnt lock
[Fri Dec 16 13:45:11 2005] [error] Writing: \nbob
[Fri Dec 16 13:45:11 2005] [error] ... no we didn't:

Hvis jeg fjerner alle rettigheder fra filen så den ikke kan åbnes, så
får jeg også helt korrekt fejlen fra fopen-linjen med. 

Af en eller anden grund mener PHP-folkene at jeg skal kunne løse dette
problem uden adgang til errno og ferror(), men hvordan gør jeg så?
Hvordan får jeg min kode til at give mere sigende fejlbeskeder end at
det bare ikke gik godt?

-- 
 Peter Makholm     |               Vi smider blade allesammen - hele tiden
 sslug@sslug |                      som et konstant spirende efterår
 http://hacking.dk |                 Og hele tiden vokser nye frugter frem
                   |                  og vi finder nogen til at plukke dem
                   |                            -- Tilt, Perkussive popler


 
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] *