Rechercher une fonction PHP

Examples

Example #1 Yar Server Example

<?php

/* assume this page can be accessed by http://example.com/operator.php */

class Operator {

    
/**
     * Add two operands
     * @param interge 
     * @return interge
     */
    
public function add($a$b) {
        return 
$this->_add($a$b);
    }

    
/**
     * Sub 
     */
    
public function sub($a$b) {
        return 
$a $b;
    }

    
/**
     * Mul
     */
    
public function mul($a$b) {
        return 
$a $b;
    }

    
/**
     * Protected methods will not be exposed
     * @param interge 
     * @return interge
     */
    
protected function _add($a$b) {
        return 
$a $b;
    }
}

$server = new Yar_Server(new Operator());
$server->handle();
?>

Example #2 Access the server in borwser(GET request)

The above example will output something similar to:

Yar Server Info

Example #3 Yar Client Example

<?php
$client 
= new yar_client("http://example.com/operator.php");

/* call directly */
var_dump($client->add(12));

/* call via call */
var_dump($client->call("add", array(32)));


/* __add can not be called */
var_dump($client->_add(12));
?>

The above example will output something similar to:

int(3)
int(5)
PHP Fatal error:  Uncaught exception 'Yar_Server_Exception' with message 'call to api Operator::_add() failed' in *

Example #4 Yar Concurrent Client Example

<?php
function callback($ret$callinfo) {
    echo 
$callinfo['method'] , " result: "$ret "\n";
}

/* register async call to remote services */
Yar_Concurrent_Client::call("http://example.com/operator.php""add", array(12), "callback");
Yar_Concurrent_Client::call("http://example.com/operator.php""sub", array(21), "callback");
Yar_Concurrent_Client::call("http://example.com/operator.php""mul", array(22), "callback");

/* sent all request and wait for response */
Yar_Concurrent_Client::loop();
?>

The above example will output something similar to:

mul result: 4
sub result: 1
add result: 3
Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-yar.examples.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut