src/Simple.php
public function removeLineFromFile($line, $fh)
    {

        // initialize the array for the PIDs found in the PID file
        $lines = array();

        // initialize the flag if the line has been found
        $found = false;

        // rewind the file pointer
        rewind($fh);

        // read the lines with the PIDs from the PID file
        while (($buffer = fgets($fh, 4096)) !== false) {
            // remove the new line
            $buffer = trim($buffer);
            // if the line is the one to be removed, ignore the line
            if ($line === $buffer) {
                $found = true;
                continue;
            }

            // add the found PID to the array
            $lines[] = $buffer;
        }

        // query whether or not, we found the line
        if (!$found) {
            throw new LineNotFoundException(sprintf('Line %s can not be found', $line));
        }

        // empty the file and rewind the file pointer
        ftruncate($fh, 0);
        rewind($fh);

        // append the existing lines to the file
        foreach ($lines as $ln) {
            if (fwrite($fh, $ln . PHP_EOL) === false) {
                throw new \Exception(sprintf('Can\'t write %s to file', $ln));
            }
        }
    }
public function removeLineFromFile($line, $fh)
    {

        // initialize the array for the PIDs found in the PID file
        $lines = array();

        // initialize the flag if the line has been found
        $found = false;

        // rewind the file pointer
        rewind($fh);

        // read the lines with the PIDs from the PID file
        while (($buffer = fgets($fh, 4096)) !== false) {
            // remove the new line
            $buffer = trim($buffer);
            // if the line is the one to be removed, ignore the line
            if ($line === $buffer) {
                $found = true;
                continue;
            }

            // add the found PID to the array
            $lines[] = $buffer;
        }

        // query whether or not, we found the line
        if (!$found) {
            throw new LineNotFoundException(sprintf('Line %s can not be found', $line));
        }

        // empty the file and rewind the file pointer
        ftruncate($fh, 0);
        rewind($fh);

        // append the existing lines to the file
        foreach ($lines as $ln) {
            if (fwrite($fh, $ln . PHP_EOL) === false) {
                throw new \Exception(sprintf('Can\'t write %s to file', $ln));
            }
        }
    }
public function removeLineFromFile ( $ line , $ fh ) { // initialize the array for the PIDs found in the PID file $ lines = array ( ) ; // initialize the flag if the line has been found $ found = false ; // rewind the file pointer rewind ( $ fh ) ; // read the lines with the PIDs from the PID file while ( ( $ buffer = fgets ( $ fh , 4096 ) ) !== false ) { // remove the new line $ buffer = trim ( $ buffer ) ; // if the line is the one to be removed, ignore the line if ( $ line === $ buffer ) { $ found = true ; continue ; } // add the found PID to the array $ lines [ ] = $ buffer ; } // query whether or not, we found the line if ( ! $ found ) { throw new LineNotFoundException ( sprintf ( 'Line %s can not be found' , $ line ) ) ; } // empty the file and rewind the file pointer ftruncate ( $ fh , 0 ) ; rewind ( $ fh ) ; // append the existing lines to the file foreach ( $ lines as $ ln ) { if ( fwrite ( $ fh , $ ln . PHP_EOL ) === false ) { throw new \ Exception ( sprintf ( 'Can\'t write %s to file' , $ ln ) ) ; } } }
Remove's the passed line from the file with the passed name.

@param string   $line The line to be removed
@param resource $fh   The file handle of the file the line has to be removed

@return void
@throws \Exception Is thrown, if the file doesn't exists, the line is not found or can not be removed
Remove s the passed line from the file with the passed name .