跨服务器保存iis日志方法

 更新时间:2016年11月25日 16:26  点击:1444

用php教程可扩展特性实现可以远程保存游戏用户日志信息,这里我暂时叫他tlog(与文件服务器建立tcp/ip连接,当然最好是udp),目前定义了三个函数
tlog_init,tlog_record,tlog_close
tlog_init(ip,port)用来连接文件服务器其中ip,port分别为文件服务器地址和端口
tlog_record(message,file)用户发送要记录的日志内容和日志保存的文件
tlog_close为关闭发送日志产生的socket链接

<?php
$result = tlog_init("127.0.0.1", 9734);
if ($result) {
    tlog_record("hello" . time(), '1.log');
    tlog_record("hello world" . time(), '2.log');
    tlog_close();
}
?>

我们主要修改config.m4,tlog.c,php_tlog.h实现我们要的功能
   打开config.m4,
  删除 php_arg_enable(tlog, whether to enable tlog support, 行开始注释dnl
  删除[  --enable-tlog           enable tlog support]) 行开始注释dnl
  打开php_tlog.h 增加


php_function(tlog_init);
php_function(tlog_record);
php_function(tlog_close);

外t_log.c见包
  以上步骤后进入tlog目录执行
   ./你的php安装目录/bin/phpize 我的目录为/usr/local/webserver/php5.3.3,则该命令./usr/local/webserver/php5.3.3/bin/phpize
./configure --with-php-config=/usr/local/webserver/php5.3.3/bin/php-config
make
sudo make install  (因为我使用的ubuntu,所以带了sudo主要是php安装目录创建扩展时的权限问题)

修改php.ini增加tlog.so扩展

查看phpinfo();

<body>
<form action="curlupload.php" method="post" enctype="multipart/form-data">
<div>
<label for="upload">select file</label>
<input name="upload" type="file" />
<input type="submit" name="submit" value="upload" />
</div>
</form>
</body>
</html>
<?
if (isset($_post['submit'])) {
 if (!empty($_files['upload']['name'])) {
     $ch = curl_init();
     $localfile = $_files['upload']['tmp_name'];
     $fp = fopen($localfile, 'r');
     curl_setopt($ch, curlopt_url, 'ftp://ftp_login:password@ftp.domain.com/'.$_files['upload']['name']);
     curl_setopt($ch, curlopt_upload, 1);
     curl_setopt($ch, curlopt_infile, $fp);
     curl_setopt($ch, curlopt_infilesize, filesize($localfile));
     curl_exec ($ch);
     $error_no = curl_errno($ch);
     curl_close ($ch);
        if ($error_no == 0) {
            $error = 'file uploaded succesfully.';
        } else {
            $error = 'file upload error.';
        }
 } else {
        $error = 'please select a file.';
 }
}
?>

好了下面封闭成类了

<?php
class curl_ftp
{
   
    private $ftpname;          //ftp用户名
    private $ftppaw;           //ftp密码
    private $urlftp;           //ftp地址
    private $filename;         //文件名
   
    public __construct($name, $password, $ftp)
    {
        $this->ftpname  = $name;
        $this->ftppaw   = $password;
        $this->urlftp   = $ftp;
 //    $this->filename = $filename;
    }
   
    public function getftp()
    {
        if (isset($_post['submit']))
      {
         if (!empty($_files['upload']['name']))
         {
             $ch = curl_init();
             $this->filename = $_files['upload']['tmp_name'];
             $fp = fopen($this->filename, 'r');
             curl_setopt($ch, curlopt_url, $this->ftp.$this->filename);
            curl_setopt($ch, curlopt_userpwd, "$name:password");
             curl_setopt($ch, curlopt_upload, 1);
             curl_setopt($ch, curlopt_infile, $fp);
             curl_setopt($ch, curlopt_infilesize, filesize($this->filename));
             curl_exec ($ch);
             $error_no = curl_errno($ch);
             curl_close ($ch);
                if ($error_no == 0)
                {
                    $error = '文件上传成功';
                }
                else
                {
                    $error = '文件上传失败';
                }
         }
         else
         {
                $error = '未选择文件';
         }
  }
    }
}

用户提交自己的信息后,保存在数据库教程中,程序每一次读取当前结果时都要判断一次,如用户可设置几秒钟时参加竞拍,竞拍多少次,并且可以设置前面有多少人竞拍后我才参加,都是一些人性化的功能//自动出价

function auto($second,$gid,$shutuid)
{
        global $table_prefix;
        //取出此商品已经竞拍次数
        $maxnumber=0;
        $unumber=array();
        $query=mysql教程_query("select id,uid from `".$table_prefix."buylog` where gid=".$gid);
        while($rows=mysql_fetch_assoc($query))
        {
                $maxnumber++;
                if(isset($unumber[$rows['uid']]))
                {
                        $unumber[$rows['uid']]++;
                }
                else
                {
                        $unumber[$rows['uid']]=0;
                }
        }
       
        //取出自动竞拍的会员
        $sql="select uid,username,number,second,maxnumber,gid,ip from `".$table_prefix."autobuy` where gid=".$gid;
        $query=mysql_query($sql);
        $allow=array();
        $shutuid=explode(',',$shutuid);
        while($rows=mysql_fetch_assoc($query))
        {
                $seconds=explode(',',$rows['second']);
                $unumber[$rows['uid']]=isset($unumber[$rows['uid']])?$unumber[$rows['uid']]:0;
                if(in_array($second,$seconds) && !in_array($rows['uid'],$shutuid) && $rows['maxnumber']<=$maxnumber && $rows['number']>$unumber[$rows['uid']]) //包含时刻,并且不在黑名单,符合此会员竞拍次数设置
                {
                        $allow[]=$rows['uid'];
                }
        }
        $allowuser=array();
        if($allow)
        {
                $query=mysql_query('select uid,username,money,ip from `'.$table_prefix.'user` where uid in ('.implode(',',$allow).')');
                while($rows=mysql_fetch_assoc($query))
                {
                        $allowuser[]=$rows;
                }
        }
        unset($allow,$sql,$number,$maxnumber,$shutuid,$query,$u);
        return $allowuser;
}
这是一款简单PHP图片上传类带图片显示代码,应该可以说是上传文件最简单的上传类了,可以设置要显示图片高度与宽度,文件大小等。

uploadimg.class.php文件

 代码如下 复制代码

class upload
{
var $upload_name;
var $upload_tmp_address;
var $upload_server_name;
var $upload_filetype ;
var $file_type;
var $file_server_address;
var $image_w=900; //要显示图片的宽
var $image_h=350; //要显示图片的高
var $upload_file_size;
var $upload_must_size= 50000; //允许上传文件的大小,自己设置
function upload_file()
{
$this->upload_name = $_files["file"]["name"]; //取得上传文件名
$this->upload_filetype = $_files["file"]["type"];
$this->upload_server_name = date("y_m_dh_i_s").$this->upload_name;
$this->upload_tmp_address = $_files["file"]["tmp_name"]; //取得临时地址
$this->file_type = array("image/gif","image/pjpeg"); //允许上传文件的类型
$this->upload_file_size = $_files["file"]["size"]; //上传文件的大小
if(in_array($this->upload_filetype,$this->file_type))
{ if($this->upload_file_size < $this->upload_must_size)
{
echo("上传成功,谢谢支持");
$this->file_server_address = "d:www.111cn.netupload/".$this->upload_server_name;
move_uploaded_file($this->upload_tmp_address,$this->file_server_address);//从temp目录移出
echo("<img src=$this->file_server_address width=$this->image_w height=$this->image_h/>"); //显示图片


}
else
{
echo("文件容量太大");
}
}
else
{
echo("不支持此文件类型,请重新选择");
}

}

}


html上传代码

 代码如下 复制代码

<form id="form1" name="upload" enctype="multipart/form-data" method="post" action="upload.php">
<input type="hidden" name="max_file_size " />
<input type="file" name="file" />
<input type="submit" name="submit" value="提交" />
</form>


调用方法
upload.php

 代码如下 复制代码

inlcude('uploadimg.class.php');

$dd = new upload;
$dd->upload_file();

 

文章收藏了三款php计数器代码,他们三个都有一个同共点就是全部无需数据库,而是利用了文本文件来实例网页浏览计数哦。
 代码如下 复制代码
<?php
//计数器
function countx($file="count.dat"){
if(file_exists($file)){
$fp=fopen($file,"r");
$numx=fgets($fp,10);
fclose($fp);
$numx++;
//以上四行代码可以用一条表达式代替:$numx=file_get_contents($file)+1;
}
else{
$numx=1;}
file_put_contents($file,$numx);//当文件不存在时,这函数会自动创建文件,而且会自动把参数转成字符串写入。
echo $numx;
/*整个函数体可以用两条表达式代替:file_exists($file)?file_put_contents($file,file_get_contents($file)+1):file_put_contents($file,"1");readfile($file);
*/
}
//函数调用
countx();
?>

代码二

 代码如下 复制代码

<?php
  
  
  $counterfile = "balong.txt";//存储数值的文件名几路径
  
  function displaycounter($counterfile) {
   $fp = fopen($counterfile,"rw");
   $num = fgets($fp,5);
   $num += 1;
   print "您是第 "."$num"." 个看巴泷计数器的家伙";
   exec( "rm -rf $counterfile");
   exec( "echo $num > $counterfile");
  }
  
  if (!file_exists($counterfile)) {
   exec( "echo 0 > $counterfile");
  }
  
  displaycounter($counterfile);
  
  ?>


代码三

 代码如下 复制代码

<?php
  
  
  $counterfile = "www.111cn.net.txt";//存储数值的文件名几路径
  
  function displaycounter($counterfile) {
   $fp = fopen($counterfile,"rw");
   $num = fgets($fp,5);
   $num += 1;
   print "您是第 "."$num"." 个看巴泷计数器的家伙";
   exec( "rm -rf $counterfile");
   exec( "echo $num > $counterfile");
  }
  
  if (!file_exists($counterfile)) {
   exec( "echo 0 > $counterfile");
  }
  
  displaycounter($counterfile);
  
  ?>

[!--infotagslink--]

相关文章

  • php 中file_get_contents超时问题的解决方法

    file_get_contents超时我知道最多的原因就是你机器访问远程机器过慢,导致php脚本超时了,但也有其它很多原因,下面我来总结file_get_contents超时问题的解决方法总结。...2016-11-25
  • php抓取网站图片并保存的实现方法

    php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
  • HTTP 408错误是什么 HTTP 408错误解决方法

    相信很多站长都遇到过这样一个问题,访问页面时出现408错误,下面一聚教程网将为大家介绍408错误出现的原因以及408错误的解决办法。 HTTP 408错误出现原因: HTT...2017-01-22
  • Android子控件超出父控件的范围显示出来方法

    下面我们来看一篇关于Android子控件超出父控件的范围显示出来方法,希望这篇文章能够帮助到各位朋友,有碰到此问题的朋友可以进来看看哦。 <RelativeLayout xmlns:an...2016-10-02
  • ps把文字背景变透明的操作方法

    ps软件是现在非常受大家喜欢的一款软件,有着非常不错的使用功能。这次文章就给大家介绍下ps把文字背景变透明的操作方法,喜欢的一起来看看。 1、使用Photoshop软件...2017-07-06
  • intellij idea快速查看当前类中的所有方法(推荐)

    这篇文章主要介绍了intellij idea快速查看当前类中的所有方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-09-02
  • Mysql select语句设置默认值的方法

    1.在没有设置默认值的情况下: 复制代码 代码如下:SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_timeFROM userinfoLEFT JOIN region ON userinfo.adm_regionid = region.id 结果:...2014-05-31
  • js导出table数据到excel即导出为EXCEL文档的方法

    复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ht...2013-10-13
  • mysql 批量更新与批量更新多条记录的不同值实现方法

    批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
  • Laravel 调试工具 laravel-debugbar 打印日志消息

    laravel-debugbar 调试工具的教程小编整理了几篇不错的教程,今天我们来看一篇Laravel 调试工具 laravel-debugbar 打印日志消息例子,希望文章对各位有帮助。 其实不...2016-11-25
  • ps怎么制作倒影 ps设计倒影的方法

    ps软件是一款非常不错的图片处理软件,有着非常不错的使用效果。这次文章要给大家介绍的是ps怎么制作倒影,一起来看看设计倒影的方法。 用ps怎么做倒影最终效果&#819...2017-07-06
  • js基础知识(公有方法、私有方法、特权方法)

    本文涉及的主题虽然很基础,在许多人看来属于小伎俩,但在JavaScript基础知识中属于一个综合性的话题。这里会涉及到对象属性的封装、原型、构造函数、闭包以及立即执行表达式等知识。公有方法 公有方法就是能被外部访问...2015-11-08
  • 安卓手机wifi打不开修复教程,安卓手机wifi打不开解决方法

    手机wifi打不开?让小编来告诉你如何解决。还不知道的朋友快来看看。 手机wifi是现在生活中最常用的手机功能,但是遇到手机wifi打不开的情况该怎么办呢?如果手机wifi...2016-12-21
  • PHP 验证码不显示只有一个小红叉的解决方法

    最近想自学PHP ,做了个验证码,但不知道怎么搞的,总出现一个如下图的小红叉,但验证码就是显示不出来,原因如下 未修改之前,出现如下错误; (1)修改步骤如下,原因如下,原因是apache权限没开, (2)点击打开php.int., 搜索extension=ph...2013-10-04
  • c#中分割字符串的几种方法

    单个字符分割 string s="abcdeabcdeabcde"; string[] sArray=s.Split('c'); foreach(string i in sArray) Console.WriteLine(i.ToString()); 输出下面的结果: ab de...2020-06-25
  • js控制页面控件隐藏显示的两种方法介绍

    javascript控制页面控件隐藏显示的两种方法,方法的不同之处在于控件隐藏后是否还在页面上占位 方法一: 复制代码 代码如下: document.all["panelsms"].style.visibility="hidden"; document.all["panelsms"].style.visi...2013-10-13
  • 连接MySql速度慢的解决方法(skip-name-resolve)

    最近在Linux服务器上安装MySql5后,本地使用客户端连MySql速度超慢,本地程序连接也超慢。 解决方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。原因是默认安装的MySql开启了DNS的反向解析。如果禁用的话就不能...2015-10-21
  • C#方法的总结详解

    本篇文章是对C#方法进行了详细的总结与介绍,需要的朋友参考下...2020-06-25
  • Zend studio文件注释模板设置方法

    步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
  • EXCEL数据上传到SQL SERVER中的简单实现方法

    EXCEL数据上传到SQL SERVER中的方法需要注意到三点!注意点一:要把EXCEL数据上传到SQL SERVER中必须提前把EXCEL传到服务器上.做法: 在ASP.NET环境中,添加一个FileUpload上传控件后台代码的E.X: 复制代码 代码如下: if...2013-09-23