File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 1919 */ 
2020class  Mailer
2121{
22+     /** 
23+      * DO NOT REMOVE THIS PROPERTY ! 
24+      * 
25+      * When it is garbage collected, the lock will be released. 
26+      * And the lock must only be released at the end of PHP process, 
27+      * never at the end of the method. 
28+      * 
29+      * @var false|resource 
30+      */ 
31+     private  $ lock ;
32+ 
2233    public  function  __construct (
2334        private  readonly  EntityManager   $ entityManager ,
2435        private  readonly  MessageRepository   $ messageRepository ,
@@ -119,12 +130,12 @@ private function acquireLock(): void
119130    {
120131        $ lockFile  = 'data/tmp/mailer.lock ' ;
121132        touch ($ lockFile );
122-         $ lock  = fopen ($ lockFile , 'r+b ' );
123-         if  ($ lock  === false ) {
133+         $ this -> lock  = fopen ($ lockFile , 'r+b ' );
134+         if  ($ this -> lock  === false ) {
124135            throw  new  Exception ('Could not read lock file. This is not normal and might be a permission issue ' );
125136        }
126137
127-         if  (!flock ($ lock , LOCK_EX  | LOCK_NB )) {
138+         if  (!flock ($ this -> lock , LOCK_EX  | LOCK_NB )) {
128139            $ message  = LogRepository::MAILER_LOCKED ;
129140            _log ()->info ($ message );
130141
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments