diff options
-rw-r--r-- | it.class | 6 | ||||
-rw-r--r-- | it_dbi.class | 2 | ||||
-rw-r--r-- | it_mail.class | 11 | ||||
-rw-r--r-- | it_url.class | 10 | ||||
-rw-r--r-- | test/it_url.testserver.php | 4 | ||||
-rwxr-xr-x | test/it_url_slow.t | 7 |
6 files changed, 23 insertions, 17 deletions
@@ -1050,8 +1050,8 @@ static function time() /** * Output formatted and localized date - * @param format optional format (default is 2007-01-02 03:04:05). - * Other formats are "date", "datetime", "time". + * @param format optional format to be passed to date(), default "Y-m-d H:i:s" + * Other formats are "date", "datetime" and "time" in local language * Formats can be qualified with language, e.g. "date:en" * Special formats without language support are "icsdate", "icsdatetime". * @param stamp optional unix timestamp (default is now). @@ -1266,7 +1266,7 @@ static function json_encode($data, $p = []) */ static function json_decode($json, $p = []) { - return ($data = json_decode($json, $p['assoc'])) === null && trim($json) != 'null' ? it::error((array)$p['it_error'] + ['title' => "invalid json: " . json_last_error(), 'body' => $json]) : $data; + return ($data = json_decode($json, $p['assoc'])) === null && trim($json) != 'null' ? it::error((array)$p['it_error'] + ['title' => "invalid json: " . json_last_error_msg(), 'body' => $json]) : $data; } /** diff --git a/it_dbi.class b/it_dbi.class index bd3e2e8..0eaced2 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -828,7 +828,7 @@ function store($tags = array()) * Update current record or a number of records given by where condition * @param $tags key => value pairs (these have priority over changes in member vars) * @param $where condition to select records to be modified (if not current record) - * @return number of modified records (or false on error). WARNING: read LIMIT docs before using it + * @return number of modified records (or false on error). can be 0 if data already there. also read LIMIT docs * Does not destroy internal state of last select() call */ function update($tags = array(), $where = null) diff --git a/it_mail.class b/it_mail.class index 11a4252..3d57bc3 100644 --- a/it_mail.class +++ b/it_mail.class @@ -575,22 +575,17 @@ static function check_email($email, $checkmailbox = false) $finished = false; $connected = 0; - if (function_exists('stream_set_timeout')) - $timeout = 'stream_set_timeout'; - else - $timeout = 'socket_set_timeout'; - foreach ($mx as $mxhost => $dummy_weight) { if ($fp = @fsockopen($mxhost, $port, $dummy_errno, $dummy_errstr, 5)) { $connected++; - $timeout($fp, 45); + stream_set_timeout($fp, 45); $answer = ''; if (it_mail::send_smtp_cmd($fp, '', $answer) && it_mail::send_smtp_cmd($fp, "HELO $fromdomain", $answer) && it_mail::send_smtp_cmd($fp, "MAIL FROM: <$from>", $answer)) { - $timeout($fp, 2); + stream_set_timeout($fp, 2); $timeoutok = ($domain != 'bluewin.ch'); if (it_mail::send_smtp_cmd($fp, "RCPT TO: <$email>", $answer, $timeoutok, 500)) # 450 is often used for Greylisting @@ -602,7 +597,7 @@ static function check_email($email, $checkmailbox = false) $finished = true; } - $timeout($fp, 0, 1); + stream_set_timeout($fp, 0, 1); it_mail::send_smtp_cmd($fp, 'RSET', $answer); diff --git a/it_url.class b/it_url.class index 8af61ae..0679727 100644 --- a/it_url.class +++ b/it_url.class @@ -100,6 +100,8 @@ static function _postprocess($data, $p) * @param $p['filemtime'] Add HTTP header to only fetch when newer than this, otherwise return true instead of data * @param $p['accept_encoding'] Contents of the "Accept-Encoding: " header. Enables decoding of the response. Set to null to disable, "" (default) for all supported encodings. * @param $p['protocols'] Array of protocols to accept, defaults to ['http', 'https'], @see curl_opts for other values + * @param $p['user'] Username for basic HTTP authentication + * @param $p['pass'] Password for basic HTTP authentication * * Problem handling * @param $p['retries'] Number of retries if download fails, default 1 @@ -314,8 +316,6 @@ function request($p=array()) curl_setopt($curl, CURLOPT_URL, $url->url); } - - # FIXME 2025-01 NG just use CURLOPT_MAXFILESIZE if we have curl 8.4 $content = ""; if ($p['maxlength'] && !$p['writefunction']) { @@ -339,7 +339,7 @@ function request($p=array()) $body = $origbody = $p['maxlength'] && $got ? $content : $got; $this->curlinfo = curl_getinfo($curl); - EDC('curlinfo', $this->curlinfo); + EDC('curlinfo', $this->curlinfo, substr($got, 0, 2048)); if ($body !== false || curl_errno($curl) == 23) { @@ -710,8 +710,8 @@ static function get_cache($p = array()) $isnight = date('H') >= 1 && date('H')*3600 + date('i')*60 < $p['cleanbefore']; if (time() - @filemtime($p['cachedir'] . "/cleaned") > ($isnight ? 80000 : 2*80000)) { - it::file_put($p['cachedir'] . "/cleaned", ""); # touch could have permission problems - $maxagemin = intval($p['maxage']/60); + $maxagemin = round($p['maxage']/60, 2); + it::file_put($p['cachedir'] . "/cleaned", "$maxagemin\n"); exec("nohup bash -c 'cd {$p['cachedir']} && for i in [0-9a-f][0-9a-f]; do sleep 20; ionice -c 3 find \$i -mmin +$maxagemin -type f -delete; done' </dev/null >/dev/null 2>&1 &"); } diff --git a/test/it_url.testserver.php b/test/it_url.testserver.php index ca5300c..e59a81a 100644 --- a/test/it_url.testserver.php +++ b/test/it_url.testserver.php @@ -66,8 +66,12 @@ switch ($_SERVER['PHP_SELF']) break; case "/repeat": + if ($_REQUEST['compressed']) + ob_start('ob_gzhandler'); for ($i = 0; $i < $_REQUEST['num']; $i++) echo $_REQUEST['string']; + if ($_REQUEST['compressed']) + ob_end_flush(); break; case "/empty": diff --git a/test/it_url_slow.t b/test/it_url_slow.t index 00bbc2f..a5fd348 100755 --- a/test/it_url_slow.t +++ b/test/it_url_slow.t @@ -69,6 +69,13 @@ if (!$res || !$res2) handle_server( ok( + !it_url::get(['url' => "http://$host/repeat?string=abcdefghijklmnop&num=10&compressed", 'maxlength' => 100, 'retries' => 0, 'it_error' => false]), + 'it_url::get() fails for response larger than maxlength even if compressed response is smaller' + ) +); + +handle_server( + ok( it_url::get(U("http://$host/repeat", ['string' => "abc", 'num' => 1024 * 1024])) == str_repeat("abc", 1024 * 1024), 'it_url::get() handles large response' ) |