PHP扩展SOAP实例(WSDL)

php 的 soap 返回数组:

services.php文件:

<?php
class services {  
  /**
    * Getdnstatus one string from each other
    * 
    * @param string $dn The first string of the subtraction
    * @return array The status of the tel
   */
  public function getdnstatus($dn){
  	if($dn == "8101"){
  		$status_arr = array("1","通话","1");
  	}else{
  		$status_arr = array("0","空闲","0");
  	}
  	return serialize($status_arr);
  }
}  
  $server = new SoapServer('service.wsdl', array('soap_version' => SOAP_1_2));  
  $server->setClass("services");  
  $server->handle();  
?>

service.wsdl文件:

<?xml version='1.0' encoding='UTF-8'?>

<!-- WSDL file generated by Zend Studio. -->

<definitions name="service" targetNamespace="urn:service" xmlns:typens="urn:service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
	<message name="getdnstatus">
		<part name="dn" type="xsd:string"/>
	</message>
	<message name="getdnstatusResponse">
		<part name="getdnstatusReturn" type="xsd:anyType"/>
	</message>
	<portType name="servicesPortType">
		<operation name="getdnstatus">
			<documentation>
				Getdnstatus one string from each other
			</documentation>
			<input message="typens:getdnstatus"/>
			<output message="typens:getdnstatusResponse"/>
		</operation>
	</portType>
	<binding name="servicesBinding" type="typens:servicesPortType">
		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
		<operation name="getdnstatus">
			<soap:operation soapAction="urn:servicesAction"/>
			<input>
				<soap:body namespace="urn:service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			</input>
			<output>
				<soap:body namespace="urn:service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			</output>
		</operation>
	</binding>
	<service name="serviceService">
		<port name="servicesPort" binding="typens:servicesBinding">
			<soap:address location="http://10.1.7.153/soap/services.php"/>
		</port>
	</service>
</definitions>

客户端文件:client.php

<?php
  //$client = new SoapClient('http://10.1.7.153/soap/service.wsdl');   
  $client = new SoapClient("http://10.1.7.153/soap/services.php?WSDL");  
  try {  
  	$result = array();
	$result = $client->getdnstatus('8101');
	var_dump(unserialize($result));
  } catch(SoapFault $e) {  
	print "Sorry an error was caught executing your request: {$e->getMessage()}";  
  } 
?>

引用:https://my.oschina.net/u/1176605/blog/167114

腾讯QQ用的国家省市数据

从QQ安装目录得到的数据文件,是xml格式,用SimpleXML解析入库很简单。

LocList.xml

$file = APP_PATH . '/../doc/LocList.xml';
$xml = simplexml_load_file($file);
$model = AbstractModel::getInstance();
$tableCountry = $model->getTable('position_country');
$tableProvince = $model->getTable('position_province');
$tableCity = $model->getTable('position_city');
foreach ($xml->children() as $child) {
    $attr = $child->attributes();
    $code = $attr['Code']->__toString();
    if ($code == 1) {
        continue;
    }
    $name = $attr->Name->__toString();
    $rowCountry = $tableCountry->fetchRow(array(
        'name=?' => $name
    ));
    if (! isset($rowCountry)) {
        $rowCountry = $tableCountry->createRow();
        $rowCountry->name = $name;
        $rowCountry->save();
    }
    foreach ($child->children() as $v1) {
        $attr = $v1->attributes();
        if (! empty($attr->Name)) {
            $stateName = $attr->Name->__toString();
        } else {
            $stateName = '全部';
        }
        $rowState = $tableProvince->fetchRow(array(
            'country_id=?' => $rowCountry->id,
            'province_name=?' => $stateName
        ));
        if (! isset($rowState)) {
            $rowState = $tableProvince->createRow();
            $rowState->country_id = $rowCountry->id;
            $rowState->province_name = $stateName;
            $rowState->save();
        }
        $rowState->province_id = $rowState->id;
        $rowState->save();
        foreach ($v1->children() as $v2) {
            $attr = $v2->attributes();
            $cityName = $attr->Name->__toString();
            $rowCity = $tableCity->fetchRow(array(
                'province_id=?' => $rowState->id,
                'city_name=?' => $cityName
            ));
            if (! isset($rowCity)) {
                $rowCity = $tableCity->createRow();
                $rowCity->province_id = $rowState->id;
                $rowCity->city_name = $cityName;
                $rowCity->save();
            }
            $rowCity->city_id = $rowCity->id;
            $rowCity->save();
        }
        echo "$namet$stateNamen";
    }
}

 

php7 安装xhprof

网上找了一下就两个版本

https://github.com/Yaoguais/phpng-xhprof 这个能用,但是很不稳定,基本没发玩。

https://github.com/RustJason/xhprof/tree/php7 这个直接编译就不通过。

最终找了个商业公司开发的,有增值服务,免费服务已经和xhprof一模一样了,完全够用

https://tideways.io/profiler/xhprof-for-php7-php5.6 (https://github.com/tideways/php-profiler-extension)

使用xhprof默认UI的时候需要注意一点

  1. 如果没有使用默认数据目录需要手动修改XHProfRuns_Default类构造方法中的dir,否则会找不到需要展示的数据。

依赖的第三方命令:yum install graphviz

session_start(): Unable to clear session lock record

php 5.6升级到php 7.0之后memcached session经常出现session_start(): Unable to clear session lock record错误,配套的新版memached配置已经更新,memcached.sess_lock_wait_min=1000,memcached.sess_lock_wait_max=30000,这个问题还是随机性出现,目前有3种解决办法

  1. php7.0.12之后memcached.sess_lock_expire设置一个明确的值,没有亲测,据github网友测试可用。
  2. session_write_close(),不管session的值有没有变化都要session_write_close(),没有亲测。一般session用的都是框架(我用的ZF1),这种方法不是很优美。
  3. php7之后增加了一个新的session配置session.lazy_write,这个默认是true,设置成false解决问题,亲测。
    if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
        ini_set('session.lazy_write', 0);
    }

     

参考:

https://github.com/php-memcached-dev/php-memcached/issues/269

MacOS ZendStudio(Eclipse) 字体小解决

MacOS下zend studio的explorer字体是无法调整的,在外接显示器上字体小的一B,真是日了狗了,经过一番研究终于完美解决。

Finder->应用程序,找到Zend Studio,右键点击“显示包内容”,打开Contents/Eclipse/ZendStudio.ini,找到

-Dorg.eclipse.swt.internal.carbon.smallFonts

在行首加#注释掉,保存。然后启动Zend Studio 字体大小终于他妈恢复正常了。

参考文档:

http://stackoverflow.com/questions/3124629/how-can-i-configure-the-font-size-for-the-tree-item-in-the-package-explorer-in-e

http://t-machine.org/index.php/2011/08/21/fix-eclipses-fonts-on-os-x/