今天使用HessianPHP

今天要做一个bbs的API不知道七夜怎么样的,要我用HessianPHP下载了个看看代码!

确实他的机制很好,等有时间好好看看,把自己的写的代码贴出来,大家看下!

service.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
include_once('../HessianService.php');
 
class bbs_api{
 function bbs($id,$num="10"){// id格式为  x,y,z num为数量
  $this->opendb();
  $s_sql = "SELECT * FROM cdb_threads WHERE fid IN($id) ORDER BY lastpost DESC LIMIT $num";
  $r_query = mysql_query( $s_sql );
  while ( FALSE !== ( $a_rec = mysql_fetch_assoc( $r_query ) ) ){
   $show[] = $a_rec;
  }
  return $show;
 }
 function opendb(){
  $dbname = "club";
  $conn = mysql_connect("localhost","club", "club_test");
  if(!$conn) die(mysql_error());
  @mysql_select_db($dbname, $conn);
  if(mysql_errno()) die(mysql_error());
    return $conn;
  }
 
}
$service = &new HessianService();
$service->registerObject(new bbs_api);
$service->displayInfo = true;
$service->service();
?>

test.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
 
function println($var=''){
 //print_r($var);
 if ( is_array($var) ){
 
  foreach($var as $v){
   echo($v['subject']."
");
  }
 }else{
  echo($var);
 }
}
 
function printlnbold($var=''){
 echo "<strong>$var</strong>
";
}
include_once('../HessianClient.php');
 
Hessian::errorReporting(HESSIAN_SILENT);
 $url = 'http://192.168.0.9/test/server/test/service.php';
 $proxy = &new HessianClient($url);
 println( $proxy->bbs("12,15","100") );
if(Hessian::error()){
 println();
 printlnbold("There were errors in the connection:");
 $error = Hessian::error();
 println( $error->message);
 var_dump($error);
}
 
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注