browser lang:en
L'originale di questo documento si trova su http://jsonrpcphp.org/
JSON-RPC PHP è una coppia di classi scritte in PHP che implementano rispettivamente le funzionalità client e server del protocollo JSON-RPC. Obiettivo del progetto è il completo incaplsulamento della tecnica JSON-RPC all'interno del PHP.
Attraverso queste classi, è possibile offrire alla rete i metodi dei propri oggetti come RPC (server) e/o usufruire dei servizi RPC esattamente come se fossero oggetti locali.L'uso delle classi JSON-RPC PHP è estremamente semplice e mantiene intatto lo spirito di JSON:
Esempio
L'esercizio proposto in questa pagina consiste nella realizzazione di un sistema server-side e di un sistema client-side per l'utilizzo delle stesse funzionalità.
I due casi, come si vede, sono del tutto indipendenti nella logica e sono complementari solo per le esigenze dell'esercizio.
Server
Supponiamo di aver realizzato una classe example che svolga alcune operazioni nel sistema locale.Le operazioni potrebbero essere una richiesta di informazioni:
public function giveMeSomeData($param);
public function changeYourState($state);
public function writeSomething($something);
require_once 'example.php';
$myExample = new example();
require_once 'jsonRPCServer.php';
require 'example.php';
$myExample = new example();
jsonRPCServer::handle($myExample)
or print 'no request';
public function writeSomething($something);
public function writeSomething($something) {
throw new Exception('writeSomething method
is not available for RPC');
}
require_once 'jsonRPCServer.php';
require 'example.php';
require 'restrictedExample.php';
$myExample = new restrictedExample();
jsonRPCServer::handle($myExample)
or print 'no request';
require_once 'jsonRPCClient.php';
$myExample = new jsonRPCClient('http://localhost/server.php');
require_once 'example.php';
$myExample = new example();
// performs some basic operation
echo 'Attempt to perform basic operations
'."\n";
try {
echo 'Your name is '.$myExample->giveMeSomeData('name').'
'."\n";
$myExample->changeYourState('I am using this function from the local environement');
echo 'Your status request has been accepted
'."\n";
} catch (Exception $e) {
echo nl2br($e->getMessage()).'
'."\n";
}
// performs some strategic operation, locally allowed
echo '
Attempt to store strategic data
'."\n";
try {
$myExample->writeSomething('Strategic string!');
echo 'Strategic data succefully stored';
} catch (Exception $e) {
echo nl2br($e->getMessage());
}
require_once 'jsonRPCClient.php';
$myExample = new jsonRPCClient('http://jsonrpcphp.org/server.php');
// performs some basic operation
echo 'Attempt to perform basic operations
'."\n";
try {
echo 'Your name is '.$myExample->giveMeSomeData('name').'
'."\n";
$myExample->changeYourState('I am using this function from the network');
echo 'Your status request has been accepted
'."\n";
} catch (Exception $e) {
echo nl2br($e->getMessage()).'
'."\n";
}
// performs some strategic operation, locally allowed
echo '
Attempt to store strategic data
'."\n";
try {
$myExample->writeSomething('Strategic string!');
echo 'Strategic data succefully stored';
} catch (Exception $e) {
echo nl2br($e->getMessage());
}
Per i piú smemorati, una lista di comandi principali usati con linux cd : cambia la directory corrente. ls : mostra il…
in:Scripts e tutorials (0 commenti)Con l'avvento di caffeine molti webmaster si sono trovati a dover rivedere tutte le strategie SEO per i…
in:Scripts e tutorials (0 commenti)Questo è un widget di jQuery per il nuovo social network di Google-Buzz-che è possibile incorporare ovunque per…
in:Scripts e tutorials (0 commenti)Questo é un pratico codificatore/decodificatore/decriptatore (chiamatelo come volete) di password inserite nei file di configurazione .ste su dreamweaver function…
in:Scripts e tutorials (0 commenti)Il PageRank è un algoritmo che usa Google per valutare la credibilità e l'autorevolezza delle pagine Web. Il…
in:Scripts e tutorials (8 commenti)Con questo script possiamo limitare il download di un file dal nostro server php; il limite di velocitá…
in:Scripts e tutorials (0 commenti)Alcuni host hanno disabilitati nei settaggi del.ini i comandi allow_url_fopen. Questo significa anche non poter usare i vantaggi…
in:Scripts e tutorials (2 commenti)Gli SHORT URLS fanno ormai parte di quelle cose di internet che ci suonono terribilmente familiari; per capirci…
in:Scripts e tutorials (0 commenti)
