<?php
class socketChajian extends Chajian
{
	//UDP服务器主机，不需要修改
	private $serverhost = '127.0.0.1';
	
	//UDP服务端口，数字类型
	private $serverport = 782;			
	
	/**
	*	UDP发送文本
	*/
	public function udpsend($str)
	{
		if(!function_exists('socket_create'))return '没有开启Socket组件';
		$sock 	= socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
		$len 	= strlen($str);
		$bo 	= socket_sendto($sock, $str, $len, 0, $this->serverhost, $this->serverport);
		socket_close($sock);
		return $bo;
	}
	
	/**
	*	运行php命令，会有窗口
	*/
	public function runphp($str)
	{
		$cmd = 'php '.ROOT_PATH.'/api.php '.$str.'';
		return $this->udpsend($cmd);
	}
	/**
	*	运行php命令，无窗口
	*/
	public function runphps($str)
	{
		$cmd = 'amb '.ROOT_PATH.'/api.php '.$str.'';
		return $this->udpsend($cmd);
	}
}