PHP函数,每次执行脚本时将变量增加1

编程入门 行业动态 更新时间:2024-10-25 16:21:28
本文介绍了PHP函数,每次执行脚本时将变量增加1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每次执行脚本时,都可以将变量或数组增加1。

Is it possible to increment a variable or array by 1 each time the script is executed.

例如,执行脚本并设置变量到 $ increment ='1';

An example would be, I execute the script and it sets a variable to $increment = '1';

然后我关闭脚本,30分钟后回来执行

I then close the script and come back 30 min later to execute the script again.

这次变量需要 $ increment ='2';

脚本将每30分钟从cron运行总共8次。

The script will be run from cron every 30 minutes for a total of 8 times.

第8次执行后,变量将需要要回退到 $ increment ='1';

After the 8th execution the variable would need to be rewound back to $increment = '1';

这是否可以通过会话?是否可以为cli sapi设置会话?

Is this possible through session? Can session be setup for the cli sapi ?

或者更容易输出带有下一个增量编号的文本文件,只需从文本文件中取出值?

Or would it be easier to output a text file with the next increment number and just pull the value from the text file?

所有的帮助是值得赞赏的。

All help is appreciated.

推荐答案

变量的值到脚本调用之间的非易失性源。此外,你必须考虑种族条件,如果(通常情况下)脚本几乎可以在同一时间调用。

You will have to persist the value of the variable to a non-volatile source between calls to the script. Furthermore, you'll have to consider race conditions if (as is often the case) the script can be called at almost the same time.

是将您的变量存储在维护事务安全的数据库中。即使是最便宜的webhosters提供某种形式的数据库,将满足这个要求...具体取决于您的特定设置。

The best bet for this, is to store your variable in a database that maintains transactional safety. Even most cheap webhosters offer some form of database that will meet this requirement ... the specifics depend on your particular setup.

更多推荐

PHP函数,每次执行脚本时将变量增加1

本文发布于:2023-10-22 22:30:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   时将   脚本   函数   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!