PHP。只执行一次代码,

时间:2017-07-02 12:00:07

标签: php

我是PHP新手,刚开始学习它。有这个问题,我现在已经工作了很长一段时间,但似乎没有任何工作。 好吧,问题是我有一段网页代码,我只需要执行一次。我的意思是,当第一个客户端查看网页并停止为查看该页面的第二个和其他客户端工作时,必须执行代码。 我试过“包含”和“需要一次”但这些执行代码每次运行一次。我也尝试过使用会话但是这种情况下代码也会为每个客户端执行一次。 而且,是的,我知道我可以使用标志和检查数据库来使这项工作,但我想知道PHP是否处理它 所以我有点卡在这里。

我们知道PHP是服务器端语言;因此,它是否具有执行代码一次并将结果存储在其全局空间中的任何功能?

这是我的代码,我从excel读取数据,然后创建我的项目数组。

// foreach row
// I read $col1 ..$col6 from excel for each row
new itemdata($col1,$col2,$col3,$col4,$col5,$col6);


class itemdata
{
    public $item;
    public $cat;
    public $unit;
    public $prec;
    public $alarmType;
    public $order;
    static $items=array();

    function __construct($item,$cat,$unit,$prec,$alarm,$order)
    {
        $this->item = $item ;
        $this->cat = $cat;
        $this->unit = $unit;
        $this->prec = $prec ;
        $this->alarmType = $alarm;
        $this->order = $order;

        array_push(self::$items,$this);
    }
// And some methods for searching declared array 'items'

我需要一次执行此代码。
感谢您的帮助。

0 个答案:

没有答案
相关问题