當前位置: 首頁>>代碼示例>>PHP>>正文


PHP stream_get_line函數代碼示例

本文整理匯總了PHP中stream_get_line函數的典型用法代碼示例。如果您正苦於以下問題:PHP stream_get_line函數的具體用法?PHP stream_get_line怎麽用?PHP stream_get_line使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了stream_get_line函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: read

 public function read($length = 3600, $ending = "\r\n")
 {
     if (!is_resource($this->_resource)) {
         return false;
     }
     return stream_get_line($this->_resource, $length, $ending);
 }
開發者ID:unionofrad,項目名稱:li3_queue,代碼行數:7,代碼來源:Beanstalk.php

示例2: performHandshake

 protected function performHandshake()
 {
     $request = '';
     do {
         $buffer = stream_get_line($this->socket, 1024, "\r\n");
         $request .= $buffer . "\n";
         $metadata = stream_get_meta_data($this->socket);
     } while (!feof($this->socket) && $metadata['unread_bytes'] > 0);
     if (!preg_match('/GET (.*) HTTP\\//mUi', $request, $matches)) {
         throw new ConnectionException("No GET in request:\n" . $request);
     }
     $get_uri = trim($matches[1]);
     $uri_parts = parse_url($get_uri);
     $this->request = explode("\n", $request);
     $this->request_path = $uri_parts['path'];
     /// @todo Get query and fragment as well.
     if (!preg_match('#Sec-WebSocket-Key:\\s(.*)$#mUi', $request, $matches)) {
         throw new ConnectionException("Client had no Key in upgrade request:\n" . $request);
     }
     $key = trim($matches[1]);
     /// @todo Validate key length and base 64...
     $response_key = base64_encode(pack('H*', sha1($key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
     $header = "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: websocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept: {$response_key}\r\n" . "\r\n";
     $this->write($header);
     $this->is_connected = true;
 }
開發者ID:islandmyth,項目名稱:websocket-php,代碼行數:26,代碼來源:Server.php

示例3: DoTest

function DoTest($fp, $delim)
{
    echo "Delimiter:  " . $delim . "\n";
    rewind($fp);
    echo "\t" . stream_get_line($fp, 10, $delim) . "\n";
    echo "\t" . stream_get_line($fp, 10, $delim) . "\n";
}
開發者ID:badlamer,項目名稱:hhvm,代碼行數:7,代碼來源:bug43522.php

示例4: makeRequest

 public function makeRequest($out)
 {
     if (!$this->connectSocket()) {
         // reconnect if not connected
         return FALSE;
     }
     fwrite($this->socket, $out . "\r\n");
     $line = fgets($this->socket);
     $line = explode(" ", $line);
     $status = intval($line[0], 10);
     $hasResponse = true;
     if ($status === 200) {
         // several lines followed by empty line
         $endSequence = "\r\n\r\n";
     } else {
         if ($status === 201) {
             // one line of data returned
             $endSequence = "\r\n";
         } else {
             $hasResponse = FALSE;
         }
     }
     if ($hasResponse) {
         $response = stream_get_line($this->socket, 1000000, $endSequence);
     } else {
         $response = FALSE;
     }
     return array("status" => $status, "response" => $response);
 }
開發者ID:rabiulkhan,項目名稱:news_graphics,代碼行數:29,代碼來源:CasparServerConnector.php

示例5: import_table_wpdb

 /**
  * Imports a single database table using the WordPress database class.
  * @access public
  * @param  string $table The table to import
  * @return array  An array of the results.
  */
 public function import_table_wpdb($table, $replace_url = '')
 {
     $live_url = site_url();
     $fh = fopen("{$this->backup_dir}revisr_{$table}.sql", 'r');
     $size = filesize("{$this->backup_dir}revisr_{$table}.sql");
     $status = array('errors' => 0, 'updates' => 0);
     while (!feof($fh)) {
         $query = trim(stream_get_line($fh, $size, ';' . PHP_EOL));
         if (empty($query)) {
             $status['dropped_queries'][] = $query;
             continue;
         }
         if ($this->wpdb->query($query) === false) {
             $status['errors']++;
             $status['bad_queries'][] = $query;
         } else {
             $status['updates']++;
             $status['good_queries'][] = $query;
         }
     }
     fclose($fh);
     if ('' !== $replace_url) {
         $this->revisr_srdb($table, $replace_url, $live_url);
     }
     if (0 !== $status['errors']) {
         return false;
     }
     return true;
 }
開發者ID:acchs,項目名稱:test,代碼行數:35,代碼來源:class-revisr-db-import.php

示例6: read_sequence

function read_sequence($id)
{
    $id = '>' . $id;
    $ln_id = strlen($id);
    $fd = STDIN;
    // reach sequence three
    do {
        $line = stream_get_line($fd, 250, "\n");
        // if EOF then we couldn't find the sequence
        if (feof($fd)) {
            exit(-1);
        }
    } while (strncmp($line, $id, $ln_id) !== 0);
    ob_start();
    // for repeated string concatenations, output buffering is fastest
    // next, read the content of the sequence
    while (!feof($fd)) {
        $line = stream_get_line($fd, 250, "\n");
        if (!isset($line[0])) {
            continue;
        }
        $c = $line[0];
        if ($c === ';') {
            continue;
        }
        if ($c === '>') {
            break;
        }
        // append the uppercase sequence fragment,
        // must get rid of the CR/LF or whatever if present
        echo $line;
    }
    return strtoupper(ob_get_clean());
}
開發者ID:bennett000,項目名稱:benchmarksgame,代碼行數:34,代碼來源:knucleotide.php-4.php

示例7: ask

function ask($question, $default = null, $validator = null)
{
    global $STDIN, $STDOUT;
    if (!is_resource($STDIN)) {
        $STDIN = fopen('php://stdin', 'r');
    }
    if (!is_resource($STDOUT)) {
        $STDOUT = fopen('php://stdout', 'w');
    }
    $input_stream = $STDIN;
    while (true) {
        print WARN . "- {$question}";
        if ($default !== null) {
            print MAGENTA . "[{$default}]";
        }
        print NORMAL . ": ";
        $answer = stream_get_line($input_stream, 10240, "\n");
        if (!$answer && $default !== null) {
            return $default;
        }
        if ($answer && (!$validator || $validator($answer))) {
            return $answer;
        }
    }
}
開發者ID:ahastudio,項目名稱:moniwiki,代碼行數:25,代碼來源:utils.php

示例8: check_ip

 private function check_ip()
 {
     if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
         $ip = $_SERVER['HTTP_CLIENT_IP'];
     } elseif (isset($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     $this->current_ip = md5($ip);
     if (!file_exists($this->config['ips'])) {
         if (is_writable('.')) {
             touch($this->config['ips']);
         } else {
             exit('Could not create "' . $this->config['ips'] . '"');
         }
     }
     if ($file = fopen($this->config['ips'], 'r')) {
         while ($line = stream_get_line($file, 128, "\n")) {
             if (strpos($line, $this->current_ip) !== FALSE) {
                 $this->counted = TRUE;
                 break;
             }
         }
         fclose($file);
     } else {
         exit('Could not open "' . $this->config['ips'] . '"');
     }
     if (!$this->counted) {
         file_put_contents($this->config['ips'], $this->current_ip . "\n", FILE_APPEND);
     }
 }
開發者ID:edy,項目名稱:Simple-Counter,代碼行數:32,代碼來源:counter.php

示例9: parse

 public function parse()
 {
     $this->_line_number = 1;
     $this->_char_number = 1;
     $eof = false;
     while (!feof($this->_stream) && !$eof) {
         $pos = ftell($this->_stream);
         $line = stream_get_line($this->_stream, $this->_buffer_size, $this->_line_ending);
         $ended = (bool) (ftell($this->_stream) - strlen($line) - $pos);
         // if we're still at the same place after stream_get_line, we're done
         $eof = ftell($this->_stream) == $pos;
         $byteLen = strlen($line);
         for ($i = 0; $i < $byteLen; $i++) {
             if ($this->_emit_file_position) {
                 $this->_listener->file_position($this->_line_number, $this->_char_number);
             }
             $this->_consume_char($line[$i]);
             $this->_char_number++;
         }
         if ($ended) {
             $this->_line_number++;
             $this->_char_number = 1;
         }
     }
 }
開發者ID:hyuuhit,項目名稱:jsonstreamingparser,代碼行數:25,代碼來源:Parser.php

示例10: index

 public function index()
 {
     $RESPONSE_END_TAG = "<END/>";
     if (isset($_POST['command_line'])) {
         $addr = gethostbyname("localhost");
         $client = stream_socket_client("tcp://{$addr}:2014", $errno, $errorMessage);
         if ($client === false) {
             throw new UnexpectedValueException("Failed to connect: {$errorMessage}");
         } else {
             fwrite($client, $_POST['command_line']);
             $server_response = stream_get_line($client, 1024, $RESPONSE_END_TAG);
             fclose($client);
             $data = $server_response;
             //write to file
             $myfile = fopen("evaluate_output.txt", "a") or die("Unable to open file!");
             fwrite($myfile, $data . PHP_EOL);
             fclose($myfile);
             //write on the html page
             header('Content-Type: application/json');
             echo json_encode(array('response' => $server_response));
         }
     } else {
         header('Content-Type: application/json');
         echo json_encode(array('response' => 'Missing parameters : Please fill all the required parameters ! ', 'others' => ''));
     }
 }
開發者ID:AnesBendimerad,項目名稱:PDC---3---Bloom-Filter,代碼行數:26,代碼來源:commandLineController.php

示例11: index

 public function index()
 {
     if (isset($_POST['config']) && isset($_POST['command_test'])) {
         $RESPONSE_END_TAG = "<END/>";
         $addr = gethostbyname("localhost");
         $client = stream_socket_client("tcp://{$addr}:2014", $errno, $errorMessage);
         if ($client === false) {
             throw new UnexpectedValueException("Failed to connect: {$errorMessage}");
         }
         $config = $_POST['config'];
         fwrite($client, 'test ' . $_POST['command_test'] . ' ' . $config);
         $server_response = stream_get_line($client, 1024, $RESPONSE_END_TAG);
         fclose($client);
         $response_code = substr($server_response, 0, 2);
         $server_response = substr($server_response, 3, strlen($server_response));
         $msg = '';
         $time = '';
         if ($response_code == 'OK') {
             $data = explode(') ', $server_response);
             $msg = str_replace('(', '', $data[0]) . '.';
             $time = str_replace(')', '', str_replace('(', '', $data[1])) . '.';
         } else {
             $msg = 'The following error occurred : ' . str_replace(')', '', str_replace('(', '', $server_response)) . '.';
         }
         header('Content-Type: application/json');
         echo json_encode(array('response' => nl2br($msg), 'others' => $time));
         //echo $msg."</br>".$time;
     } else {
         header('Content-Type: application/json');
         echo json_encode(array('response' => 'Missing parameters : Please fill all the required parameters ! ', 'others' => ''));
     }
 }
開發者ID:AnesBendimerad,項目名稱:PDC---3---Bloom-Filter,代碼行數:32,代碼來源:testcontroller.php

示例12: readline

 function readline()
 {
     $line = '';
     do {
         if ($this->eol) {
             $more = stream_get_line($this->stream, $this->blocksize, $this->eol);
         } else {
             $more = fgets($this->stream, $this->blocksize);
         }
         // Sockets may return boolean FALSE for EOF and empty string
         // for client disconnect.
         if ($more === false && feof($this->stream)) {
             break;
         } elseif ($more === '') {
             throw new Exception\ClientDisconnect();
         }
         $line .= $more;
         $pos = ftell($this->stream);
         // Check if $blocksize bytes were read, which indicates that
         // an EOL might not have been found
         if (($pos - $this->pos) % $this->blocksize == 0) {
             // Attempt to seek back to read the EOL
             if (!$this->seek(-$this->ceol, SEEK_CUR)) {
                 break;
             }
             if ($this->read($this->ceol) !== $this->eol) {
                 continue;
             }
         }
         $this->pos = $pos;
     } while (false);
     return $line;
 }
開發者ID:iHunt101,項目名稱:phlite,代碼行數:33,代碼來源:BufferedInputStream.php

示例13: read_sequence

function read_sequence($id)
{
    $id = '>' . $id;
    $ln_id = strlen($id);
    $fd = STDIN;
    // reach sequence three
    while (strpos($line, $id) === false) {
        $line = stream_get_line($fd, 64, "\n");
        // returns faster when the length is too large.
        if (feof($fd)) {
            exit(-1);
        }
    }
    // next, read the content of the sequence
    $r = '';
    while (!feof($fd)) {
        $line = stream_get_line($fd, 64, "\n");
        if (!isset($line[0])) {
            continue;
        }
        $c = $line[0];
        if ($c === ';') {
            continue;
        }
        if ($c === '>') {
            break;
        }
        $r .= $line;
    }
    return strtoupper($r);
}
開發者ID:bennett000,項目名稱:benchmarksgame,代碼行數:31,代碼來源:knucleotide.php-2.php

示例14: getWeatherData

function getWeatherData($strURL, $strCacheFile, $intLimitHours, &$strGeographicLocation)
{
    if (!file_exists($strCacheFile) || filemtime($strCacheFile) + 60 * 60 * $intLimitHours < time()) {
        $arrCacheData = file($strURL);
        if (!$arrCacheData) {
            die('Problem Retrieving NOAA Data!  Please try your request again.');
        }
        $arrGeographicLocation = explode('"', $arrCacheData[1], 3);
        $strGeographicLocation = str_replace('"', '', $arrGeographicLocation[1]);
        $arrCacheData = array_filter($arrCacheData, "removeWeatherXMLCruft");
        $arrCacheData = array_merge($arrCacheData);
        $fdCacheFile = fopen($strCacheFile, "w");
        fputs($fdCacheFile, $strGeographicLocation . "\n");
        for ($i = 0; $i < sizeof($arrCacheData); $i++) {
            fputs($fdCacheFile, $arrCacheData[$i]);
        }
        fclose($fdCacheFile);
    }
    $arrCacheData = array();
    $fdCacheFile = fopen($strCacheFile, "r");
    $strGeographicLocation = stream_get_line($fdCacheFile, 4096, "\n");
    while (!feof($fdCacheFile)) {
        $arrCacheData[] = stream_get_line($fdCacheFile, 4096, "\n");
    }
    fclose($fdCacheFile);
    $strWeatherData = implode("\r\n", $arrCacheData);
    $strWeatherData = strip_tags(str_replace(array(',', "\r\n"), array('', ','), $strWeatherData));
    $arrCacheData = str_getcsv($strWeatherData);
    return array_chunk($arrCacheData, 3);
}
開發者ID:rafuch0,項目名稱:USGS-NOAA,代碼行數:30,代碼來源:WeatherData.php

示例15: isCssLessCompiled

 /**
  * Checks if CSS file was compiled from LESS
  *
  * @param   string  $dir    a path to file
  * @param   string  $entry  a filename
  * 
  * @return  boolean
  */
 public static function isCssLessCompiled($dir, $entry)
 {
     $file = $dir . '/' . $entry;
     $fp = fopen($file, 'r');
     $line = stream_get_line($fp, 1024, "\n");
     fclose($fp);
     return 0 === strcmp($line, self::getCssHeader());
 }
開發者ID:xfifix,項目名稱:Jenkins-Khan,代碼行數:16,代碼來源:sfLESSUtils.class.php


注:本文中的stream_get_line函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。