SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,155
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Problem in textfile cannot be deleted

    Hi, I am creating a textfile through batch file,when my textfile is created and some data on it,and when i stoped the batch file and trying to delete the textfile or renamed on it.

    it shows this error "The action cannot be completed because the file is open in php.exe"

    how can i solved this problem?


    Thank you in advance.

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2006
    Location
    Nantwich, Cheshire
    Posts
    447
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's because it hasn't been closed for whatever reason. Do you explicitly close the file once you've created and finished with it? Can you show the code?
    http://www.firenza.net - my homage to a car from the 1970s

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,155
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by droopsnoot View Post
    That's because it hasn't been closed for whatever reason. Do you explicitly close the file once you've created and finished with it? Can you show the code?
    Here is the code.


    PHP Code:


    $address 
    'xxx.xxx.x.xx';//server ip
    $port xxxx;//port

       

        
    $sock socket_create(AF_INETSOCK_STREAMSOL_TCP);

        
    socket_set_option($sockSOL_SOCKETSO_REUSEADDR1);

        
    socket_bind($sock$address$port);

        
    socket_listen($sock);

        
    $clients = array($sock);
      
        while (
    true) {
         
    $file fopen('mytxt.log','a'); 
      
            
    $read $clients;
            
    $write NULL;
            
    $except NULL;
            
    $tv_sec 0
       
            
            if (
    socket_select($read$write $except,  $tv_sec) < 1)
                continue;
           
          
            if (
    in_array($sock$read)) {
        
                
    $clients[] = $newsock socket_accept($sock);
            
                
    $key array_search($sock$read);
                unset(
    $read[$key]);
            }
           
           
            foreach (
    $read as $read_sock) {
                
    $data = @socket_read($read_sock1024PHP_NORMAL_READ);
               
                
    // check if the client is disconnected
                
    if ($data === false) {
                    
    // remove client for $clients array
                    
    $key array_search($read_sock$clients);
                    unset(
    $clients[$key]);
           
                    continue;
                }
               
             
                
    $data trim($data);
               
                if (!empty(
    $data)) {
                     
    fwrite($file,$data."\n");
                }
               
            } 
    // end of reading foreach
            
            
    fclose($file);
        }

        
    socket_close($sock);
    ?> 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •