目前已经实现了一大半了
不过在asp中,当服务器重启时application中的数据会被清空
我在自己实现的application类里面是用文件的方式共享数据
清空它的最容易的办法就是直接删除这个文件
但现在的问题我不知道什么时候apache会重启
哪位大神能给个办法?

解决方案 »

  1.   

    当服务器重启时application中的数据会被清空
    这表示 application 是存放在内存里的,也是很头疼的事情,因为必须寻找一个方法恢复他既然你已经用文件方式实现了,又何必去模拟他的缺点
      

  2.   

    这么说吧,我现在用php执行计划任务,使用了一个application变量来标识这个计划任务已经运行,要不然就成了重复运行了
    但是如果服务器重启了,那么计划任务肯定就没有执行了,但问题是因为application是以文件方式来存储的,所以说这个变量就仍然在,那么程序会认为这个计划任务仍然在执行懂我的意思了么···
      

  3.   

    那你也就放在内存你就是了
    既然你已经不是 web 方式运行了,也就没有必要再去顾忌 php 共享内存函数的兼容性了
    更一般些,你丫可以同过 apc、memcached 扩展区操纵内存
    何必自寻烦恼
      

  4.   

    这是windows平台啊···那几个内存函数不是只有linux上才能运行吗?
    我如何才能在windows平台上共享内存?
      

  5.   

    常见的编程技巧是启动后读pid文件,使用kill(0, pid)检测进程是否存活。如果存活则说明进程尚未退出,如果不存活则覆盖写pid文件并开始运行。贴个C定义,你看看windows是否有类似函数吧:SYNOPSIS
           #include <signal.h>       int kill(pid_t pid, int sig);DESCRIPTION
           The kill() function shall send a signal to a process or a group of processes specified by pid. The signal to be sent is specified by sig and  is  either
           one  from  the list given in <signal.h> or 0. If sig is 0 (the null signal), error checking is performed but no signal is actually sent. The null signal
           can be used to check the validity of pid.   ESRCH  No process or process group can be found corresponding to that specified by pid.
      

  6.   

    window 下启用 extension=php_shmop.dll函数
    shmop_close -- Close shared memory block
    shmop_delete -- Delete shared memory block
    shmop_open -- Create or open shared memory block
    shmop_read -- Read data from shared memory block
    shmop_size -- Get size of shared memory block
    shmop_write -- Write data into shared memory block示例
    <?php
    /*
     * @文件: create.php
     * @功能:将全局变量写入共享内存中
     */
     
    //定义全局变量
    $super = "hello world";//申请100字节共享内存空间
    $shm_id = shmop_open(0xff3, "c", 0644, 100);
    if (!$shm_id)
    {
     echo "申请空间失败<br>";
    }//内容写入共享内存空间
    if (shmop_write($shm_id, $super, 0))
    {
     echo "全局变量已经写入共享内存<br>";
    }
    else
    {
     echo "写入共享内存失败<br>";
    }//关闭共享内存空间
    shmop_close($shm_id);
    ?><?php
    /*
     * @文件: read.php
     * @功能:读取共享内存中的内容
     */
     
    //读100字节共享内存空间
    $shm_id = shmop_open(0xff3, "a", 0644, 100);//获取共享内存空间中的前11个字节的内容
    //create.php中 $super 变量长度为11
    $share = shmop_read($shm_id, 0, 11);echo $share;//关闭
    shmop_close($shm_id);
    ?>
      

  7.   


    太谢谢了···
    不过
    shmop_open(0xff3, "c", 0644, 100)
    这里面这个0xff3能随便写?
      

  8.   


    pid文件没毛病,posix_kill试试去吧。至于你这个system v的key,使用ftok创建, 随便指定不可移植而且说不定会和已有key重复。[User:root Time:21:02:52 Path:/home/apache/web]$ ipcs ------ Shared Memory Segments --------
    key        shmid      owner      perms      bytes      nattch     status      
    0x6c6c6536 0          root       600        4096       0                       ------ Semaphore Arrays --------
    key        semid      owner      perms      nsems     
    0x00000000 0          root       600        1         
    0x00000000 65537      root       600        1         
    0x00000000 163842     daemon     600        1         ------ Message Queues --------
    key        msqid      owner      perms      used-bytes   messages    
      

  9.   

    最终方案:<?php
    $arr=array();
    function application($key,$value="")
    {
    global $arr;
    $shm_id = shmop_open(0xff3, "c", 0644, 1024*1024);
    $byte=shmop_read($shm_id,0,1024);
    if(!$byte){
    if($byte!=""){
    $arr=unserialize($byte);
    }
    }
    if($value=="")//取值
    {
    shmop_close($shm_id);
    if(array_key_exists($key,$arr))
    {
    return $arr[$key];
    }
    return "";
    }else{
    //设置值
    $arr[$key]=$value;
    shmop_write($shm_id,serialize($arr),0);
    shmop_close($shm_id);
    }
    }application("runing","1");
    echo application("runing");
    感谢八楼,结贴!