[英]Monitoring script performance on a shared host
I'm planning to run a PHP script periodically via cron on a shared hosting provider. 我打算通过cron在共享主机提供商上定期运行PHP脚本。 Based on my localhost development, the script does not utilize too much of CPU.
基于我的本地主机开发,该脚本不占用过多的CPU。 However, I would like to monitor the script runs/usage so as not to exert excess strain on the server and hence potentially result in an account limit.
但是,我想监视脚本的运行/使用情况,以免在服务器上施加过多的压力,因此可能导致帐户限制。
What is the best way to monitor the memory and CPU usage of the script (with the additional feature of having the performance reports being e-mailed)? 监视脚本的内存和CPU使用率的最佳方法是什么(具有通过电子邮件发送性能报告的附加功能)? Since I'm on a shared host, I will not be able to install apps.
由于我位于共享主机上,因此无法安装应用程序。
Thanks 谢谢
You can write your script in the below way. 您可以通过以下方式编写脚本。 Their is a default function in php to check the memory usage but in few servers running windows, if they are disabled, their is a work around as well.
它们是php中检查内存使用情况的默认功能,但是在少数运行Windows的服务器中,如果将它们禁用,它们也可以解决。 Analyze the below code and try to get the idea.
分析下面的代码,然后尝试理解。 Hope it helps.
希望能帮助到你。
function getMemUsage()
{
if (function_exists('memory_get_usage'))
{
return memory_get_usage();
}
else if ( strpos( strtolower($_SERVER["OS"]), 'windows') !== false)
{
// Windows workaround
$output = array();
exec('tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $output);
return substr($output[5], strpos($output[5], ':') + 1);
}
else
{
return '<b style="color: red;">no value</b>';
}
}
$message = getMemUsage();
$subject = "Memory USage";
mail("xxx@xxx.com",$message,$subject);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.