@@ -106,15 +106,18 @@ private function lock(Key $key, bool $read, bool $blocking)
106106
107107 // Silence error reporting
108108 set_error_handler (function ($ type , $ msg ) use (&$ error ) { $ error = $ msg ; });
109- if (!$ handle = fopen ($ fileName , 'r+ ' ) ?: fopen ($ fileName , 'r ' )) {
110- if ($ handle = fopen ($ fileName , 'x ' )) {
111- chmod ($ fileName , 0666 );
112- } elseif (!$ handle = fopen ($ fileName , 'r+ ' ) ?: fopen ($ fileName , 'r ' )) {
113- usleep (100 ); // Give some time for chmod() to complete
114- $ handle = fopen ($ fileName , 'r+ ' ) ?: fopen ($ fileName , 'r ' );
109+ try {
110+ if (!$ handle = fopen ($ fileName , 'r+ ' ) ?: fopen ($ fileName , 'r ' )) {
111+ if ($ handle = fopen ($ fileName , 'x ' )) {
112+ chmod ($ fileName , 0666 );
113+ } elseif (!$ handle = fopen ($ fileName , 'r+ ' ) ?: fopen ($ fileName , 'r ' )) {
114+ usleep (100 ); // Give some time for chmod() to complete
115+ $ handle = fopen ($ fileName , 'r+ ' ) ?: fopen ($ fileName , 'r ' );
116+ }
115117 }
118+ } finally {
119+ restore_error_handler ();
116120 }
117- restore_error_handler ();
118121 }
119122
120123 if (!$ handle ) {
0 commit comments