Phar::startBuffering

(PHP 5 >= 5.3.0, PHP 7, PECL phar >= 1.0.0)

Phar::startBufferingStart buffering Phar write operations, do not modify the Phar object on disk

说明

public Phar::startBuffering ( void ) : void

Although technically unnecessary, the Phar::startBuffering() method can provide a significant performance boost when creating or modifying a Phar archive with a large number of files. Ordinarily, every time a file within a Phar archive is created or modified in any way, the entire Phar archive will be recreated with the changes. In this way, the archive will be up-to-date with the activity performed on it.

However, this can be unnecessary when simply creating a new Phar archive, when it would make more sense to write the entire archive out at once. Similarly, it is often necessary to make a series of changes and to ensure that they all are possible before making any changes on disk, similar to the relational database concept of transactions. the Phar::startBuffering()/Phar::stopBuffering() pair of methods is provided for this purpose.

Phar write buffering is per-archive, buffering active for the foo.phar Phar archive does not affect changes to the bar.phar Phar archive.

返回值

没有返回值。

范例

Example #1 A Phar::startBuffering() example

<?php
// make sure it doesn't exist
@unlink('brandnewphar.phar');
try {
    
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar'0'brandnewphar.phar');
} catch (
Exception $e) {
    echo 
'Could not create phar:'$e;
}
echo 
'The new phar has ' $p->count() . " entries\n";
$p->startBuffering();
$p['file.txt'] = 'hi';
$p['file2.txt'] = 'there';
$p['file2.txt']->setCompressedGZ();
$p['file3.txt'] = 'babyface';
$p['file3.txt']->setMetadata(42);
$p->setStub("<?php
function __autoload(
$class)
{
    include 'phar://myphar.phar/' . str_replace('_', '/', 
$class) . '.php';
}
Phar::mapPhar('myphar.phar');
include 'phar://myphar.phar/startup.php';
__HALT_COMPILER();"
);
$p->stopBuffering();
?>

参见

  • Phar::stopBuffering() - Stop buffering write requests to the Phar archive, and save changes to disk
  • Phar::isBuffering() - Used to determine whether Phar write operations are being buffered, or are flushing directly to disk

相关文章
php ncurses 函数 do not translate newline and carriage return / line feedphp ncurses 函数 do not flush on signal charactersphp sybase 函数 send a sybase query and do not blockphp mongodb driver bulkwrite count number of write operations in the bulkphp mongodb driver manager execute one or more write operationsphp mongodb driver server execute one or more write operations on this serverphp quick start guide dual procedural and object oriented interfacephp oci lob changes current state of buffering for the large objectphp what makes a phar a phar and not a tar or a zip? tar based pharsphp what makes a phar a phar and not a tar or a zip? zip based pharsphp phar get the real path to the phar archive on diskphp phar used to determine whether phar write operations are being buffered or are flushing directly to diskphp phar start buffering phar write operations do not modify the phar object on diskphp phar stop buffering write requests to the phar archive and save changes to diskphp phar completely remove a phar archive from disk and from memoryphp phardata dummy function phar setalias is not valid for phardata php phardata dummy function phar setdefaultstub is not valid for phardata php phardata dummy function phar setstub is not valid for phardata php solrquery returns the treshold frequency at which words will be ignored which do not occur in at least this many docsphp swoole lock try to lock a read write lock for reading and return straight away even the lock is not available.
关注编程学问公众号