本文整理汇总了PHP中gzopen函数的典型用法代码示例。如果您正苦于以下问题:PHP gzopen函数的具体用法?PHP gzopen怎么用?PHP gzopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gzopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: geoip_detect_update
function geoip_detect_update()
{
// TODO: Currently cron is scheduled but not executed. Remove scheduling.
if (get_option('geoip-detect-source') != 'auto') {
return;
}
$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz';
$download_url = apply_filters('geoip_detect2_download_url', $download_url);
$outFile = geoip_detect_get_database_upload_filename();
// Download
$tmpFile = download_url($download_url);
if (is_wp_error($tmpFile)) {
return $tmpFile->get_error_message();
}
// Ungzip File
$zh = gzopen($tmpFile, 'r');
$h = fopen($outFile, 'w');
if (!$zh) {
return __('Downloaded file could not be opened for reading.', 'geoip-detect');
}
if (!$h) {
return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
}
while (($string = gzread($zh, 4096)) != false) {
fwrite($h, $string, strlen($string));
}
gzclose($zh);
fclose($h);
unlink($tmpFile);
return true;
}
示例2: openFile
protected function openFile()
{
$this->handle = gzopen($this->filename, 'w9');
if ($this->handle === false) {
throw new \RuntimeException(sprintf('Impossible to open the file %s in write mode', $this->filename));
}
}
示例3: fopen
function fopen($filename, $mode = 'r')
{
if ($this->has_gzip()) {
return gzopen($filename, $mode);
}
return fopen($filename, $mode);
}
示例4: animetitlesUpdate
public function animetitlesUpdate()
{
$pdo = $this->pdo;
$lastUpdate = $pdo->queryOneRow('SELECT max(unixtime) as utime FROM animetitles');
if (isset($lastUpdate['utime']) && time() - $lastUpdate['utime'] < 604800) {
if ($this->echooutput) {
echo "\n";
echo $this->c->info("Last update occurred less than 7 days ago, skipping full dat file update.\n\n");
}
return;
}
if ($this->echooutput) {
echo $this->c->header("Updating animetitles by grabbing full dat AniDB dump.\n\n");
}
$zh = gzopen('http://anidb.net/api/anime-titles.dat.gz', 'r');
preg_match_all('/(\\d+)\\|\\d\\|.+\\|(.+)/', gzread($zh, '10000000'), $animetitles);
if (!$animetitles) {
return false;
}
$pdo->queryExec('DELETE FROM animetitles WHERE anidbid IS NOT NULL');
if ($this->echooutput) {
echo $this->c->header("Total of " . count($animetitles[1]) . " titles to add\n\n");
}
for ($loop = 0; $loop < count($animetitles[1]); $loop++) {
$pdo->queryInsert(sprintf('INSERT IGNORE INTO animetitles (anidbid, title, unixtime) VALUES (%d, %s, %d)', $animetitles[1][$loop], $pdo->escapeString(html_entity_decode($animetitles[2][$loop], ENT_QUOTES, 'UTF-8')), time()));
}
if ($loop % 2500 == 0 && $this->echooutput) {
echo $this->c->header("Completed Processing " . $loop . " titles.\n\n");
}
gzclose($zh);
if ($this->echooutput) {
echo $this->c->header("Completed animetitles update.\n\n");
}
}
示例5: gzcompressfile
/**
* Compress file on disk
*
* @param string $source
* @param int $level
* @return string|false
*/
function gzcompressfile($source, $level = false)
{
if (file_exists($source)) {
$dest = $source . '.gz';
$mode = 'wb' . $level;
$error = false;
if ($fp_out = gzopen($dest, $mode)) {
if ($fp_in = fopen($source, 'rb')) {
while (!feof($fp_in)) {
gzwrite($fp_out, fread($fp_in, 4096));
}
fclose($fp_in);
} else {
$error = true;
}
gzclose($fp_out);
} else {
$error = true;
}
if ($error) {
return false;
}
return $dest;
}
return false;
}
示例6: zip
/**
* Gzip a file
*
* @param string $sSourceFile Path to the source file
* @param string $sDestinationFile [optional] Path to save the zip contents.
* <p>
* If NULL, the default value is $this->getDefaultDestinationFilename($sSourceFile)
* </p>
*
* @return string Path to the saved zip file
*
* @throws FileOpenException if there is any error opening the source or output files
* @throws FileReadException if there is an error reading the source file
* @throws FileWriteException if there is an error writing the output file
*/
public function zip($sSourceFile, $sDestinationFile = null)
{
if ($sDestinationFile === null) {
$sDestinationFile = $this->getDefaultDestinationFilename($sSourceFile);
}
if (!($fh = fopen($sSourceFile, 'rb'))) {
throw new FileOpenException($sSourceFile);
}
if (!($zp = gzopen($sDestinationFile, 'wb9'))) {
throw new FileOpenException($sDestinationFile);
}
while (!feof($fh)) {
$data = fread($fh, static::READ_SIZE);
if (false === $data) {
throw new FileReadException($sSourceFile);
}
$sz = strlen($data);
if ($sz !== gzwrite($zp, $data, $sz)) {
throw new FileWriteException($sDestinationFile);
}
}
gzclose($zp);
fclose($fh);
return $sDestinationFile;
}
示例7: updateGeoIpFile
/**
* updates the GeoIP database file
* works only if directory geoip has rights 777, set it in ftp client
*/
function updateGeoIpFile()
{
global $cpd_path;
// set directory mode
@chmod($cpd_path . '/geoip', 0777);
// function checks
if (!ini_get('allow_url_fopen')) {
return 'Sorry, <code>allow_url_fopen</code> is disabled!';
}
if (!function_exists('gzopen')) {
return __('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd');
}
$gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz';
$file = $cpd_path . '/geoip/GeoIP.dat';
// get remote file
$h = gzopen($gzfile, 'rb');
$content = gzread($h, 1500000);
fclose($h);
// delete local file
if (is_file($file)) {
unlink($file);
}
// file deleted?
$del = is_file($file) ? 0 : 1;
// write new locale file
$h = fopen($file, 'wb');
fwrite($h, $content);
fclose($h);
@chmod($file, 0777);
if (is_file($file) && $del) {
return __('New GeoIP database installed.', 'cpd');
} else {
return __('Sorry, an error occurred. Try again or check the access rights of directory "geoip" is 777.', 'cpd');
}
}
示例8: import_sql
function import_sql($filename)
{
$handle = @gzopen($filename, "r");
// can open normal files, too.
$query = "";
$queries = 0;
while ($handle && !feof($handle)) {
$line = gzgets($handle, 1024);
// keep string manipulations sane
if ($line != "" && substr($line, 0, 2) != "--") {
// line doesnt start with comment
$query .= $line;
if (substr(trim($line), -1, 1) == ";") {
if (!mysql_query($query)) {
if (defined("DEBUG")) {
echo "MYSQL Error: " . mysql_error() . "<Br><br>in query: {$query}";
} else {
echo "MYSQL Error: " . mysql_error();
}
}
$query = "";
$queries++;
}
}
}
return true;
}
示例9: openResource
protected function openResource()
{
if ($this->gzip_file) {
return gzopen($this->resource, 'a');
}
return fopen($this->resource, 'a');
}
示例10: rotateLogs
/**
* Rotate all files in var/log which ends with .log
*/
public function rotateLogs()
{
$var = Mage::getBaseDir('log');
$logDir = new Varien_Io_File();
$logDir->cd($var);
$logFiles = $logDir->ls(Varien_Io_File::GREP_FILES);
foreach ($logFiles as $logFile) {
if ($logFile['filetype'] == 'log') {
$filename = $logFile['text'];
if (extension_loaded('zlib')) {
$zipname = $var . DS . $this->getArchiveName($filename);
$zip = gzopen($zipname, 'wb9');
gzwrite($zip, $logDir->read($filename));
gzclose($zip);
} else {
$logDir->cp($filename, $this->getArchiveName($filename));
}
foreach ($this->getFilesOlderThan(self::MAX_FILE_DAYS, $var, $filename) as $oldFile) {
$logDir->rm($oldFile['text']);
}
$logDir->rm($filename);
}
}
$logDir->close();
}
示例11: WRITE
function WRITE($hash, $overwrite = 0)
{
$id = $hash["id"];
$version = $hash["version"];
$dbfile = $this->FN("{$id}.{$version}");
if (!$overwrite && file_exists($dbfile)) {
return;
}
#-- read-lock
if (file_exists($dbfile)) {
$lock = fopen($dbfile, "rb");
flock($lock, LOCK_EX);
}
#-- open file for writing, secondary lock
if ($f = gzopen($dbfile, "wb" . $this->gz)) {
if (!lock) {
flock($f, LOCK_EX);
}
$r = gzwrite($f, serialize($hash));
gzclose($f);
$this->SETVER($id, $version);
$this->CACHE_ADD($id, $version);
return 1;
}
#-- dispose lock
if ($lock) {
flock($lock, LOCK_UN);
fclose($lock);
}
return 0;
}
示例12: restoreAction
function restoreAction()
{
$backupFile = new UploadedFile("backupFile");
if (!$backupFile->wasUploaded()) {
return;
}
$gzipMode = $this->request->fileType == "gzip";
$fileName = $backupFile->getTempName();
$fp = $gzipMode ? gzopen($fileName, "r") : fopen($fileName, "r");
$inString = false;
$query = "";
while (!feof($fp)) {
$line = $gzipMode ? gzgets($fp) : fgets($fp);
if (!$inString) {
$isCommentLine = false;
foreach (array("#", "--") as $commentTag) {
if (strpos($line, $commentTag) === 0) {
$isCommentLine = true;
}
}
if ($isCommentLine || trim($line) == "") {
continue;
}
}
$deslashedLine = str_replace('\\', '', $line);
if ((substr_count($deslashedLine, "'") - substr_count($deslashedLine, "\\'")) % 2) {
$inString = !$inString;
}
$query .= $line;
if (substr_compare(rtrim($line), ";", -1) == 0 && !$inString) {
$this->database->sqlQuery($query);
$query = "";
}
}
}
示例13: Open
/**
* Open a descriptor for this archive
*
* @param GitPHP_Archive $archive archive
* @return boolean true on success
*/
public function Open($archive)
{
if (!$archive) {
return false;
}
if ($this->handle) {
return true;
}
$args = array();
$args[] = '--format=tar';
$args[] = "--prefix='" . $archive->GetPrefix() . "'";
$args[] = $archive->GetObject()->GetHash();
$this->handle = $this->exe->Open($archive->GetProject()->GetPath(), GIT_ARCHIVE, $args);
// hack to get around the fact that gzip files
// can't be compressed on the fly and the php zlib stream
// doesn't seem to daisy chain with any non-file streams
$this->tempfile = tempnam(sys_get_temp_dir(), "GitPHP");
$mode = 'wb';
if ($this->compressLevel) {
$mode .= $this->compressLevel;
}
$temphandle = gzopen($this->tempfile, $mode);
if ($temphandle) {
while (!feof($this->handle)) {
gzwrite($temphandle, fread($this->handle, 1048576));
}
gzclose($temphandle);
$temphandle = fopen($this->tempfile, 'rb');
}
if ($this->handle) {
pclose($this->handle);
}
$this->handle = $temphandle;
return $this->handle !== false;
}
示例14: testCreate
public function testCreate()
{
$sitemap = new Sitemap(['maxUrlsCountInFile' => 1]);
$sitemapDirectory = $sitemap->sitemapDirectory = $this->path;
$sitemap->addModel(Category::className());
$sitemap->setDisallowUrls(['#category_2#']);
$sitemap->create();
$sitemapFileNames = array();
foreach (glob("{$sitemapDirectory}/sitemap*") as $sitemapFilePath) {
$sitemapFileNames[] = basename($sitemapFilePath);
}
$this->assertEquals($sitemapFileNames, array('sitemap.xml', 'sitemap.xml.gz', 'sitemap1.xml', 'sitemap1.xml.gz', 'sitemap2.xml', 'sitemap2.xml.gz'));
$xmlData = file_get_contents("{$sitemapDirectory}/sitemap.xml");
$this->assertNotFalse(strpos($xmlData, '<?xml version="1.0" encoding="UTF-8"?>'));
$xmlData = file_get_contents("{$sitemapDirectory}/sitemap2.xml");
$this->assertNotFalse(strpos($xmlData, '<loc>http://localhost/category_3</loc>'));
$gzSitemap = gzopen("{$sitemapDirectory}/sitemap.xml.gz", "r");
$sitemap = fopen("{$sitemapDirectory}/sitemap.xml", "r");
$this->assertEquals(fread($gzSitemap, 2000), fread($sitemap, 2000));
gzclose($gzSitemap);
fclose($sitemap);
$gzSitemap = gzopen("{$sitemapDirectory}/sitemap2.xml.gz", "r");
$sitemap = fopen("{$sitemapDirectory}/sitemap2.xml", "r");
$this->assertEquals(fread($gzSitemap, 2000), fread($sitemap, 2000));
gzclose($gzSitemap);
fclose($sitemap);
}
示例15: gzcompressfile
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) 2009-2016 pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/
function gzcompressfile($source, $level = null, $target = null)
{
// this is a very memory efficient way of gzipping files
if ($target) {
$dest = $target;
} else {
$dest = $source . '.gz';
}
$mode = 'wb' . $level;
$error = false;
$fp_out = gzopen($dest, $mode);
$fp_in = fopen($source, 'rb');
if ($fp_out && $fp_in) {
while (!feof($fp_in)) {
gzwrite($fp_out, fread($fp_in, 1024 * 512));
}
fclose($fp_in);
gzclose($fp_out);
} else {
$error = true;
}
if ($error) {
return false;
} else {
return $dest;
}
}