我正在使用一些代码并收到此错误,该脚本应该与PHP 5.2+一起使用,我正在运行5.4.27。
完成错误Fatal error: 'continue' operator with non-constant operand is no longer supported in C:\xampp\htdocs\inc.php on line 326
第326行,continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
完整的代码部分,
public function scrape ( $announce = null, $hash_info = null, $timeout = self::timeout ) {
$packed_hash = urlencode( pack('H*', $hash_info ? $hash_info : $this->hash_info() ) );
$handles = $scrape = array();
if ( ! function_exists( 'curl_multi_init' ) )
return self::set_error( new Exception( 'Install CURL with "curl_multi_init" enabled' ) );
$curl = curl_multi_init();
foreach ( (array) ($announce ? $announce : $this->announce()) as $tier )
foreach ( (array) $tier as $tracker ) {
$tracker = str_ireplace( array( 'udp://', '/announce', ':80/' ), array( 'http://', '/scrape', '/' ), $tracker );
if ( isset( $handles[$tracker] ) )
continue;
$handles[$tracker] = curl_init( $tracker . '?info_hash=' . $packed_hash );
curl_setopt( $handles[$tracker], CURLOPT_RETURNTRANSFER, true );
curl_setopt( $handles[$tracker], CURLOPT_TIMEOUT, $timeout );
curl_multi_add_handle( $curl, $handles[$tracker] );
}
do {
while ( ( $state = curl_multi_exec( $curl, $running ) ) == CURLM_CALL_MULTI_PERFORM );
if( $state != CURLM_OK )
continue;
while ( $done = curl_multi_info_read( $curl ) ) {
$info = curl_getinfo( $done['handle'] );
$tracker = array_shift( explode( '?', $info['url'], 2 ) );
if ( empty( $info['http_code'] ) )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
elseif ( $info['http_code'] != 200 )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request failed (' . $info['http_code'] . ' code)' ), true );
$stats = self::decode_data( curl_multi_getcontent( $done['handle'] ) );
curl_multi_remove_handle( $curl, $done['handle'] );
$scrape[$tracker] = empty( $stats['files'] ) ?
self::set_error( new Exception( 'Empty scrape data' ), true ) :
array_shift( $stats['files'] ) + ( empty( $stats['flags'] ) ? array() : $stats['flags'] );
}
} while ( $running );
curl_multi_close( $curl );
return $scrape;
}
答案 0 :(得分:3)
continue
用于跳过当前循环的其余部分,并从下一次迭代开始。您可以在其后面加上一个数字,以告知要跳过多少循环级别到迭代结束。如果您没有指定号码,则defailt为1。
但是你所背后的continue
不是一个数字,而是一些陈述。首先尝试执行语句,然后执行continue;
所以改变:
if ( empty( $info['http_code'] ) )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
elseif ( $info['http_code'] != 200 )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request failed (' . $info['http_code'] . ' code)' ), true );
成:
if ( empty( $info['http_code'] ) ) {
$scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
continue;
} elseif ( $info['http_code'] != 200 ) {
$scrape[$tracker] = self::set_error( new Exception( 'Tracker request failed (' . $info['http_code'] . ' code)' ), true );
continue;
}