一:PHP本身的SOAP
所有的webservice都包括服务端(server)和客户端(client)。
要使用php本身的soap首先要把该拓展安装好并且启用。下面看具体的code
首先这是服务端实现:
class test
{
function show()
{
return 'the data you request!';
}
}
function getUserInfo($name)
{
return 'fbbin';
}
//实例化的参数手册上面有,这个是没有使用wsdl的,所以第一个参数为null,如果有使用wsdl,那么第一个参数就是这个wsdl文件的地址。
$server = new SoapServer(null, array('uri' ='http://soap/','location'='http://localhost/test/server.php'));
$server->setClass('test');
//$server->addFunction('getUserInfo');
$server->handle();
?>
然后是客户端
$soap = new SoapClient(null, array('location'='http://localhost/test/server.php','uri' ='http://soap/'));
echo $soap->show();
//得到:'the data you request!'
//echo $soap->getUserInfo('sss');
就这么简单,当时这只是一个很简单的例子,其实很多的通信机制都是这么去实现的!
////////////////////////////////////////////////////////////////////////////////
二:PHPRPC
首先到官网(http://www.phprpc.org/zh_CN/ )上面去下载最新版的phprpc,解压之后会有相关的文件,我们把文件进行划分(服务端和客户端文件)如下:
服务端文件:
dhparams
dhparams.php
phprpc_server.php
bigint.php
compat.php
phprpc_date.php
xxtea.php
客户端文件:
phprpc_client.php
bigint.php
compat.php
phprpc_date.php
xxtea.php
我们把服务端文件放在服务端文件夹中,然后把客户端文件放在客户端文件夹中,之后再服务端文件夹中新建个文件(server.php)作为服务,然后再客户端新建个文件(client.php)作为客户端,各自代码如下:
server端:
include_once"phprpc_server.php"; //加载phprpc文件
$server = new PHPRPC_Server();
$server->add('getUser');
$server->setDebugMode(true);
$server->start();
function getUser( )
{
return ‘the data you request!';
}
client端:
[code]
include_once "phprpc_client.php";
$client = new PHPRPC_Client('http://127.0.0.1/phpservice/phprpcserver/server.php');
$data = $client->getUser();
var_dump($data);
//得到:the data you request!
这上面提到wsdl之后会讲到如何生成。
////////////////////////////////////////////////////////////////////////////////
三:开源的NUSOAP
首先到网上去下载最新版的nusoap,现在的最新版本是0.9.5的,解压之后会得到一个lib文件夹,把这个文件分别放到服务端和客户端各一份,然后再服务端和客户端分别建立server.php和client.php文件,作为通信文件。
服务端文件如下:
ini_set("soap.wsdl_cache_enabled", 0);//关闭缓存
require_once("lib/nusoap.php"); //加载nusoap文件
$server = new soap_server;
$server->configureWSDL('nusoasp');//设定服务的名称,使用的wsdl来通信,如果不适用wsdl将会更简单,网上有很多的例子
$server->register('getUserInfo', array('name'="xsd:string", 'email'="xsd:string"), array('return'="xsd:string"));
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service( $HTTP_RAW_POST_DATA );
function getUserInfo($name, $email)
{
return ‘the data you request!';
}
客户端文件如下:
require_once("lib/nusoap.php");
$client = new soapclient('http://localhost/phpservice/nusoapserver/server.php?wsdl');
$pagram = array('fbbin', 'fbbin@foxmail.com');
$string = $client->call('getUserInfo', $pagram);
//得到:the data you request!
///////////////////////////////////////////////////////////////////////////////
四:HessianPHP
hessian其实我个人认为他不是一个webservice,只能说是类似而已。因为它不具备webservice的那些特性。它支持的语言比较多我们现在只需要研究php版本的HessianPHP就行了,下载最新版本是v2.0.3的,解压之后会得到一个src的目录,这个目录使我们需要使用的一个核心文件夹。
我们把名字重命名为HessianPHP然后分别分别放到server和client端,然后分别建立server.php和client.php文件。
server端:
include_once 'HessianPHP/HessianService.php';//加载核心文件
class TestService
{
public function __construct()
{
}
public function add($numa, $numb)
{
return $numa + $numb;
}
public function check()
{
return 'fbbiin@gmail.com';
}
}
$test = new TestService();
$hessian = new HessianService( $test, array('displayInfo' => true) );
$hessian->handle();//注意这里不是网上的$hessian->service(),可能是版本不一样,改了吧!我也是看了源码才知道!
?>
client 端:
include_once 'HessianPHP/HessianClient.php';
$url = "http://localhost/phpservice/hessianserver/server.php";
$options = new HessianOptions();
$client = new HessianClient( $url, $options );
$num = $client->add( 3, 5 );
echo $num;//得到:8;
echo $client->check();//得到:fbbiin@gmail.com;
以上四种方式为web开发过程中常用到的webservice通信方式。用的最多的是nusoap,个人感觉phprpc其实也不错,这个在性能上面和nusoap基本上差不多,只不过,phprpc在商业上是收费的。还有个hessianPHP好像是用java的,采用的二进制方式传输数据流,其实也是各有千秋啊。更多的详细资料去找百度和谷歌吧。
下面说下生成wsdl文件。
我们在webservice上面进行通信用的最多的和相对来说比较安全的就是使用wsdl了,这种文件可以自己书写,但是不是一定的大牛好像写不出来啊,因此我们需要借助一个工具zend studio来生成wsdl文件。
下面我们就来生成WSDL文件了,File->New—>Other—>Web Service—>WSDL,这样就可以新建一个WSDL文件了,如图。
然后我们就来修改WSDL文件,zeng studio为我们提供了可视化的操作,当然如果你牛的话,你当然是可以改文件代码的,其实也就几个东西, 弄懂了的话也不会太难。
做完这一步,这个WSDL文件就基本可用了,但又两个问题需要注意:
做到这一步,有可能会测试失败,可能会因为没有进行binding,这个东西有时是需要手动来完成的,在binding上右键选择Generate Binding Content(就是两个大框中间那个小框)就行了。
第二个要注意的是php的WSDL缓存,在做测试时,一般要将WSDL缓存关闭,否则你使用的有可能是原来的WSDL文件,而不是更新过的。关闭缓存有两种方法,第一种就是直接到php.ini中设置soap.wsdl_cache_enabled = 0;第二种就是在php文件中添加一条语句,ini_set("soap.wsdl_cache_enabled", "0");
做到这里,你就可以放心地测试,调用你的server程序了。
说完了,OK!

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.