Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to judge the program problems under linux by php

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

这篇文章主要介绍php如何判断linux下程序问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

具体如下:

有时候在服务器上面写一些脚本的时候,经常要放到crontab里面定时运行。时间长了就有一个问题,那就是程序重复运行消耗太多的资源,怎么处理呢?下面璞玉写了两种方法.

//第一种:用linux里面的正则匹配function ifrun($clsname,$bf = 0){ //下面进行检测,如有一个进程正在运行,则不运行 $str=shell_exec("/bin/ps ax > /home/root/".$clsname."_run.txt"); $str=shell_exec("/bin/grep -c '".$clsname.".php' /home/root/".$clsname."_run.txt"); if($bf >0) { if($str >=$bf) { return 1; } else { return 0; } } else { if ($str>=2) { return 1; } else { return 0; } }}//调用:if (ifrun('pooy',5)){ die("pooy is running");}//备注:pooy是程序pooy.php的名称!//第二种:把进程写到文件里面,然后用file函数去读取然后去匹配字符串system('ps -ef |grep wget > /root/pooy.txt');$arr=file('/root/pooy.txt');$total=count($arr);for($i=0;$i= 1 ){ echo "A same programs are running"; exit();}else{ echo "start__________________________________________________";}//注:"www/pooy" 是程序里面包含的字符串!//现在php程序在linux运行是否通畅多了呢?以上是"php如何判断linux下程序问题"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report