size() public static method

Returns the string size in bytes.
public static size ( string $string ) : integer
$string string String
return integer Size in bytes
Beispiel #1
0
 /**
  * Sends content to the client.
  *
  * @param string $content      Content
  * @param string $contentType  Content type
  * @param int    $lastModified HTTP Last-Modified Timestamp
  * @param string $etag         HTTP Cachekey to identify the cache
  */
 public static function sendContent($content, $contentType = null, $lastModified = null, $etag = null)
 {
     if (!self::$sentContentType) {
         self::sendContentType($contentType);
     }
     if (!self::$sentCacheControl) {
         self::sendCacheControl();
     }
     $environment = rex::isBackend() ? 'backend' : 'frontend';
     if (self::$httpStatus == self::HTTP_OK && (false === strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') || false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome'))) {
         // ----- Last-Modified
         if (!self::$sentLastModified && (rex::getProperty('use_last_modified') === true || rex::getProperty('use_last_modified') === $environment)) {
             self::sendLastModified($lastModified);
         }
         // ----- ETAG
         if (!self::$sentEtag && (rex::getProperty('use_etag') === true || rex::getProperty('use_etag') === $environment)) {
             self::sendEtag($etag ?: self::md5($content));
         }
     }
     // ----- GZIP
     if (rex::getProperty('use_gzip') === true || rex::getProperty('use_gzip') === $environment) {
         $content = self::sendGzip($content);
     }
     self::cleanOutputBuffers();
     header('HTTP/1.1 ' . self::$httpStatus);
     // content length schicken, damit der browser einen ladebalken anzeigen kann
     header('Content-Length: ' . rex_string::size($content));
     echo $content;
     if (function_exists('fastcgi_finish_request')) {
         fastcgi_finish_request();
     }
 }
Beispiel #2
0
 public function sendMedia($sourceCacheFilename, $headerCacheFilename, $save = false)
 {
     if ($this->asImage) {
         $src = $this->getImageSource();
     } else {
         $src = rex_file::get($this->getMediapath());
     }
     $this->setHeader('Content-Length', rex_string::size($src));
     $header = $this->getHeader();
     if (!array_key_exists('Content-Type', $header)) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $content_type = finfo_file($finfo, $this->getMediapath());
         if ($content_type != '') {
             $this->setHeader('Content-Type', $content_type);
         }
     }
     if (!array_key_exists('Content-Disposition', $header)) {
         $this->setHeader('Content-Disposition', 'inline; filename="' . $this->getMediaFilename() . '";');
     }
     if (!array_key_exists('Last-Modified', $header)) {
         $this->setHeader('Last-Modified', gmdate('D, d M Y H:i:s T'));
     }
     rex_response::cleanOutputBuffers();
     foreach ($this->header as $t => $c) {
         header($t . ': ' . $c);
     }
     echo $src;
     if ($save) {
         rex_file::putCache($headerCacheFilename, $this->header);
         rex_file::put($sourceCacheFilename, $src);
     }
 }
Beispiel #3
0
 /**
  * Writes a request to the opened connection.
  *
  * @param string          $method  HTTP method, e.g. "GET"
  * @param string          $path    Path
  * @param array           $headers Headers
  * @param string|callable $data    Body data as string or a callback for writing the body
  *
  * @throws rex_socket_exception
  *
  * @return rex_socket_response Response
  */
 protected function writeRequest($method, $path, array $headers = [], $data = '')
 {
     $eol = "\r\n";
     $headerStrings = [];
     $headerStrings[] = strtoupper($method) . ' ' . $path . ' HTTP/1.1';
     foreach ($headers as $key => $value) {
         $headerStrings[] = $key . ': ' . $value;
     }
     foreach ($headerStrings as $header) {
         fwrite($this->stream, str_replace(["\r", "\n"], '', $header) . $eol);
     }
     if (!is_callable($data)) {
         fwrite($this->stream, 'Content-Length: ' . rex_string::size($data) . $eol);
         fwrite($this->stream, $eol . $data);
     } else {
         call_user_func($data, $this->stream);
     }
     $meta = stream_get_meta_data($this->stream);
     if (isset($meta['timed_out']) && $meta['timed_out']) {
         throw new rex_socket_exception('Timeout!');
     }
     return new rex_socket_response($this->stream);
 }
Beispiel #4
0
 public function testSize()
 {
     $this->assertEquals(3, rex_string::size('aä'));
 }