Skip to content

Commit

Permalink
peer info
Browse files Browse the repository at this point in the history
  • Loading branch information
dulcedo committed May 8, 2010
1 parent 630e266 commit 1d16ed9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 43 deletions.
104 changes: 86 additions & 18 deletions YaCyAPI4.php
Expand Up @@ -37,6 +37,9 @@ class YaCyAPI {
protected $_curlArray;





//############# public API functions ismael ##########################
//
public function addJob() {
Expand Down Expand Up @@ -134,6 +137,17 @@ public function setTransferProperties() {
#indexDistribute=>on/off, indexDistributeWhileCrawling=>on/off, indexReceive=>on/off, indexReceiveBlockBlacklist=>on/off
}

public function stop() {
$peername="http://".$this->PeerURL.":".$this->PeerPort."/";
$command="Steering.html?shutdown=";
$appid=$this->PeerAppid;

$this->_dur0=microtime(true); #for measuerement
$xml = $this->peerCommandDirect($peername,$command,$appid);
$this->_dur2=microtime(true)-$this->_dur0; #time for command
}


### search specific
#########################################

Expand Down Expand Up @@ -180,16 +194,15 @@ public function setLr($n)
{
$this->Lr= $n;
}


public function stop() {
$peername="http://".$this->PeerURL.":".$this->PeerPort."/";
$command="Steering.html?shutdown=";
$appid=$this->PeerAppid;

$this->_dur0=microtime(true); #for measuerement
$xml = $this->peerCommandDirect($peername,$command,$appid);
$this->_dur2=microtime(true)-$this->_dur0; #time for command
#--------------------------------------------------------------------------------
#get results
#search
#see below
public function getMeta(){
}
public function getTitle(){
}
public function getLink(){
}


Expand All @@ -198,7 +211,53 @@ public function stop() {

public function findFirstPeer($frompeer)
{

include 'peerlist_inc.php';

$maxpeers=count($this_YaCyPeer); #local inst

$peerno=0;
while ($peerno<$maxpeers)
{
$peer=$this_YaCyPeer[$peerno][0];
$port=$this_YaCyPeer[$peerno][1];
$appid=$this_YaCyPeer[$peerno][2];
$name=$this_YaCyPeer[$peerno][3];
$peername="http://".$peer.":".$port."/";

$res=$this->setProperties($peer.":".$port,$appid,$name);
$info=$this->ping();

if ($info['status']) #port online?
{

#$res=$this->getStatus();
$command="Network.xml";
$res = $this->peerCommandDirect($peername,$command,$appid);
if ($res)
{
$result['peer']=$peer;
$result['port']=$port;
$result['appid']=$appid;

# echo "<br>found:".$peerno; print_r($info);
return $result;
$peerno=$maxpeers;
}
else
{
# echo "<br>not answering:".$peerno; print_r($info);
}
# exit;
}
else
{
# echo "<br>not found:".$peerno; print_r($info);
# exit;

}

$peerno++;
} #endwhile
}


Expand Down Expand Up @@ -304,8 +363,10 @@ public function getYconf($key) {
# returns search in simple array
public function search($s)
{
$xml=$this->getResults($s);
$resultarray=xml2array($xml); #, $get_attributes = 1, $priority = 'tag');
$xml=$this->getResults($s);

$resultarray=$this->xml2array2($xml);

$items=$resultarray['rss']['channel']['item'];
#print_r($xml);
#exit;
Expand Down Expand Up @@ -453,7 +514,10 @@ public function peerCommandDirect($peername,$command,$credentials) #="admin:yacy
$YaCyURL=$peername;
$cu=$YaCyURL.$command;
#echo "<br>CU:".$cu;
$to=2000;
#$to=2000;
$cntimeout=1;
$ctimeout=2;


$ti=microtime(true);

Expand All @@ -462,9 +526,14 @@ public function peerCommandDirect($peername,$command,$credentials) #="admin:yacy
curl_setopt($queryServer, CURLOPT_HEADER, 0);
curl_setopt($queryServer, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($queryServer, CURLOPT_USERPWD,$credentials);
curl_setopt($queryServer, CURLOPT_CONNECTTIMEOUT_MS, $to);


#MS not functional!
# curl_setopt($queryServer, CURLOPT_CONNECTTIMEOUT_MS, $to);
// connection timeout seconds
curl_setopt($queryServer, CURLOPT_CONNECTTIMEOUT, $cntimeout);
// curl timeout
curl_setopt($queryServer, CURLOPT_TIMEOUT, $ctimeout);

$holder = curl_exec($queryServer);
$this->_status = curl_getinfo($queryServer, CURLINFO_HTTP_CODE);

Expand All @@ -486,7 +555,6 @@ public function peerCommandDirect($peername,$command,$credentials) #="admin:yacy

}


################ helpers #########################

// <root>
Expand All @@ -498,7 +566,7 @@ public function peerCommandDirect($peername,$command,$credentials) #="admin:yacy
// funtion creates an array like
// array[root][child1][child1child1]

function xml2array2($contents, $get_attributes = 1, $priority = 'tag')
public function xml2array2($contents, $get_attributes = 1, $priority = 'tag')
{

if (!function_exists('xml_parser_create'))
Expand Down
10 changes: 5 additions & 5 deletions inc_crawls.php
Expand Up @@ -62,12 +62,12 @@
$status=$search->getStatus();
if (!$status)
{
$qlocal="-";
$qglobal="-";
$qlocal="-";
$qglobal="-";
} else {
$qlocal= number_format($status['localcrawlerqueue']['size'], 0, ",", ".");
$qglobal= number_format($status['limitcrawlerqueue']['size'], 0, ",", ".");
}
$qlocal= number_format($status['localcrawlerqueue']['size'], 0, ",", ".");
$qglobal= number_format($status['limitcrawlerqueue']['size'], 0, ",", ".");


$items=$search->crawlInfo();

Expand Down
4 changes: 3 additions & 1 deletion inc_onepeer.php
Expand Up @@ -83,6 +83,7 @@
$traff1=$status['traffic']['in'];
$traff2=$status['traffic']['proxy'];
$traff3=$status['traffic']['crawler'];
$traff3=round($traff3/1024,1);

# Array ( [ppm] => 36 [wordCacheSize] => 19192 [wordCacheMaxSize] => 100000 [loaderqueue] => Array ( [size] => 2 [max] => 50 ) [localcrawlerqueue] => Array ( [size] => 147040 ) [limitcrawlerqueue] => Array ( [size] => 0 ) [remotecrawlerqueue] => Array ( [size] => 0 ) [memory] => Array ( [free] => 882057936 [total] => 6534856704 [max] => 6632243200 ) [processors] => 4 [traffic] => Array ( [in] => 0 [proxy] => 0 [crawler] => 0 ) )
#print_r($status);
Expand All @@ -92,7 +93,8 @@
echo "<font size=1>&nbsp;(<font color=grey>ping:</font>".$ti1." <font color=grey>cmd:</font>".$ti2." ms)</font></td>";
if ($status)
{
echo "<td align = left title='currently used memory'>".$memp."%</td>"; # - ".$traff3."MB</td>";
echo "<td align = left title='currently crawled megabytes and used RA Memory'><font size=1><font color=grey>".$traff3."GB ".$memp."%</font></font></td>";

} else {
echo "<td align = left></td>";
}
Expand Down
53 changes: 34 additions & 19 deletions inc_peer.php
Expand Up @@ -30,30 +30,47 @@
// Include the API PHP Library
require 'YaCyAPI4.php';
#include 'JSON.php';
//-----------------------------------------------------
//
include 'peerlist_inc.php';

$peerno=$_GET['peer'];
$peer=$this_YaCyPeer[$peerno][0];
$port=$this_YaCyPeer[$peerno][1];
$appid=$this_YaCyPeer[$peerno][2];
$name=$this_YaCyPeer[$peerno][3];


# menu left
$leftmen="10"; #width% menu left
echo '<div style="float: left; width: '.$leftmen.'%;">';

$p="http://".$peer.":".$port;

echo'
<br>
<br>
<br>
<div id="navi-left">
<h1 class="screenreader">left navigation</h1>
<ul>
<li class="page_item page-item-1"><a href="" title="">search</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">crawler</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">monitor</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">control</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">restart</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">admin</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">shutdown</a></li><br>
<li class="page_item page-item-1"><a href="#" title="">YaCy home</a></li><br>
<li class="page_item page-item-1"><a href="'.$p.'/index.html?display=0" title="">search</a></li><br>
<li class="page_item page-item-1"></li><br>
<li class="page_item page-item-2"><a href="'.$p.'/CrawlStart_p.html" title="">crawlstart</a></li><br>
<li class="page_item page-item-3"><a href="'.$p.'/ContentIntegrationPHPBB3_p.html " title="">import</a></li><br>
<li class="page_item page-item-2"></li><br>
<li class="page_item page-item-3"><a href="'.$p.'/CrawlResults.html?process=5&autoforward=" title="">monitor</a></li><br>
<li class="page_item page-item-4"><a href="'.$p.'/IndexControlRWIs_p.html" title="">index</a></li><br>
<li class="page_item page-item-4"><a href="'.$p.'/AccessTracker_p.html" title="">access</a></li><br>
<li class="page_item page-item-4"></li><br>
<li class="page_item page-item-5"><a href="'.$p.'/Steering.html?restart=" title="">restart</a></li><br>
<li class="page_item page-item-6"><a href="'.$p.'/ConfigUpdate_p.html" title="">update</a></li><br>
<li class="page_item page-item-7"><a href="'.$p.'/Steering.html?shutdown=" title="">shutdown</a></li><br>
<li class="page_item page-item-1"></li><br>
<li class="page_item page-item-8"><a href="http://www.yacy.net/" title="">YaCy home</a></li><br>
</ul>
Expand All @@ -78,15 +95,6 @@
// show overview
echo "<h3><font color=grey>&nbsp;".date('d-m H:i',time())."</font></h3>";

//-----------------------------------------------------
//
include 'peerlist_inc.php';

$peerno=$_GET['peer'];
$peer=$this_YaCyPeer[$peerno][0];
$port=$this_YaCyPeer[$peerno][1];
$appid=$this_YaCyPeer[$peerno][2];
$name=$this_YaCyPeer[$peerno][3];

$t="Showing peer-name / address and time for a ping / time for executing commands / peer uptime. Click for more infos.";
#echo '<div class="blogtoy">';
Expand All @@ -96,6 +104,12 @@
$res=$search->setProperties($peer.":".$port,$appid,$name);
$info=$search->ping();








if ($info['host']) #peer defined?
{
Expand Down Expand Up @@ -228,4 +242,5 @@

} #endif peer defined

echo "</div>"; #content right
echo "</div>"; #content right

0 comments on commit 1d16ed9

Please sign in to comment.