cvs: phpweb / results.php
| From: | Rasmus Lerdorf | Date: | Wed, 01 Mar 2006 17:56:39 +0000 |
| Subject: | cvs: phpweb / results.php | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-30773@lists.php.net to get a copy of this message | ||
rasmus Wed Mar 1 17:56:39 2006 UTC
Modified files:
/phpweb results.php
Log:
Add a couple of alternative ways to get to the search backend
http://cvs.php.net/viewcvs.cgi/phpweb/results.php?r1=1.16&r2=1.17&diff_format=u
Index: phpweb/results.php
diff -u phpweb/results.php:1.16 phpweb/results.php:1.17
--- phpweb/results.php:1.16 Wed Mar 1 11:46:37 2006
+++ phpweb/results.php Wed Mar 1 17:56:39 2006
@@ -1,5 +1,5 @@
<?php
-// $Id: results.php,v 1.16 2006/03/01 11:46:37 nlopess Exp $
+// $Id: results.php,v 1.17 2006/03/01 17:56:39 rasmus Exp $
$_SERVER['BASE_PAGE'] = 'results.php';
include $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
#include $_SERVER['DOCUMENT_ROOT'] . '/include/loadavg.inc';
@@ -21,8 +21,35 @@
$valid_profiles = array('all', 'local', 'manual', 'news',
'bugs', 'pear', 'pecl', 'talks');
$scope = in_array($_GET['p'], $valid_profiles) ? $_GET['p'] : 'all';
-
-$data = file_get_contents("http://www.php.net/ws.php?profile=$scope&q=$q&lang=$l&results=$per_page&start=$s");
+$srch_host = "www.php.net";
+$srch_rqst =
"/ws.php?profile=$scope&q=$q&lang=$l&results=$per_page&start=$s";
+$url = "http://".$srch_host.$srch_rqst;
+
+if(function_exists('file_get_contents') && ini_get('allow_url_fopen'))
{
+ $data = file_get_contents($url);
+} else {
+ // Let's find another way
+ if(function_exists('curl_exec')) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ } else if(function_exists('fsockopen') && $fd = fsockopen($srch_host, 80)) {
+ $data = ''; $header = false;
+ fputs($fd,"GET $srch_rqst HTTP/1.0\r\n");
+ fputs($fd,"Host: $srch_host\r\n");
+ fputs($fd,"Connection: close\r\n\r\n");
+ while($line = fgets($fd)) {
+ if($header) $data .= $line;
+ if(strlen($line)<=2) $header = true;
+ }
+ fclose($fd);
+ } else {
+ // Redirect to www.php.net ?
+ }
+}
$res = unserialize($data);
// HTTP status line is passed on, signifies an error