


Bkjia (www.Bkjia.com) Tutorial Recently, a friend at Yahoo told me that I used to use bash csh to write scripts, but now I use PHP to write background programs. I feel that PHP’s functions are the most Complete and easy to use shell_exec to easily call the system kernel.
I exchanged some principles with him about writing background programs, which are summarized as follows.
以下为引用的内容: function connnect() { global $db; if (is_resource($db)) { mysqli_close($db); } $db = mysqli_connect("122.225.96.142", 'waihui', 'freebsd@fzm', 'waihui'); } |
First of all, we need to get rid of some of the previous thinking habits of writing web scripts. After the web script is run once, the memory is released immediately. The daemon program is different. It will run for a year or even several years.
1. As a good habit, you must run the code in an infinite loop like while (1) {}. In this way, the script will not stop as long as the code does not fail.
2. Echo cannot be used, but use log instead. Use logging instead of echo. Because echo outputs a character to the screen, if there is no output object, a fatal error will be reported.
3. If it is MYSQL, you need to reconnect to MYSQL every time.
The above is an example of connection. This code was once severely criticized by an expert. This is mainly to prevent the following things:
Mysql has restarted. The $db variable is definitely still a resource, but this resource is no longer valid. It will happen if you execute the code again:
mysql has go away such an error. This will be output to the screen, even if error reporting is turned off. This leads to the entire
The script execution error is the same as the error generated by echo.
Although it is a waste to connect to the database every time, we can only kill 1000 by mistake rather than let one go. This mistake is made by most friends
Error, many people told me that this is a mysql bug, because originally writing the file was fine, but then an error occurred when connecting to mysql.
Actually it is not a mysql bug.
4. Newly generated variables, if they are not automatically released, must be released immediately. Otherwise, over time, the program will crash. Many PHP programmers don’t have this
Regarding the concept of memory management, I think that memory is unlimited and can be used casually. When writing background programs, you must pay attention to memory management.
5. If you want to access files, you must first clearstatcache, otherwise there is a high risk of inaccurate statistics, or
It is no longer accurate to determine whether a file exists. What's even worse is that if you open files frequently, the handle value of the file will be
Keep increasing until it exceeds the maximum value of the integer, and the program cannot open the file. Many people’s programs fail once every 3 months,
There is no error or memory problem. It is very likely that the statcache is not cleared before each file operation.
Reprinted from: http://www.cnblogs.com/niniwzw/

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

适用于 Linux 的 Windows 子系统第一种选择是使用适用于 Linux 或 WSL 的 Windows 子系统,这是一个兼容层,用于在 Windows 系统上本地运行 Linux 二进制可执行文件。它适用于大多数场景,允许您在 Windows 11/10 中运行 shell 脚本。WSL 不会自动可用,因此您必须通过 Windows 设备的开发人员设置启用它。您可以通过转到设置 > 更新和安全 > 对于开发人员来完成。切换到开发人员模式并通过选择是确认提示。接下来,查找 W

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

程序员经常使用Bash命令语言创建Shell脚本来自动化手动任务。例如,他们会为各种配置、文件操作、生成构建结果和各种与DevOps相关的活动创建Bash脚本。几乎所有类Unix或基于Unix的操作系统都为用户提供预安装的Bash解释器,因此我们可以使用Bash编写更具可移植性的自动化脚本。正如我们已经知道的那样,Bash脚本编写是指使用Bash命令语言的语法、内置Bash命令和核心操作系统CLI程序(如GNU核心工具)编写一系列命令。标准且老式的Bash脚本通常执行一些命令并在终端上显示纯文本

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
