① php如何把自身進程設置為系統進程
進程管理-防止進程成為僵屍進程
創建好了進程,那麼怎麼對子進程進行管理呢?
使用信號,對子進程的管理,一般有兩種情況:(推薦學習:PHP編程從入門到精通)
posix_kill():此函數並不能顧名思義,它通過向子進程發送一個信號來操作子進程,在需要要時可以選擇給子進程發送進程終止信號來終止子進程;
pcntl_waitpid():等待或返回fork的子進程狀態,如果指定的子進程在此函數調用時已經退出(俗稱僵屍進程),此函數將立刻返回,並釋放子進程的所有系統資源,此進程可以避免子進程變成僵屍進程,造成系統資源浪費;
孤兒進程:父進程掛了,子進程被pid=1的init進程接管(wait/waitpid),直到子進程自身生命周期結束被系統回收資源和父進程 採取相關的回收操作
僵屍進程:子進程exit退出,父進程沒有通過wait/waitpid獲取子進程狀態,子進程佔用的進程號等描述資源符還存在,產生危害:例如進程號是有限的,無法釋放進程號導致未來可能無進程號可用
**父進程中使用:pcntl_wait或者pcntl_waitpid的目的就是防止worker成為僵屍進程
作用:使用pcntl_wait()後,在子進程死掉後,父進程也會被停止**
最後我們通過下圖來簡單的總結和描述這個多進程實現的過程:
.png
進程管理-進程間通信
隊列:如Redis,推薦
socket:推薦
管道:實現復雜,且管道(pipe),使用文件形式存在,存在硬碟IO性能瓶頸
信號:承載信息量少,不好管理
進程管理-切換為守護進程
使用&實現
php deadloop.php &
相關資源:Nginx使用的php-fpm的兩種進程管理方式及優化-其它代碼類資源...
打開CSDN APP,看更多技術內容
php 進程管理,PHP 進程管理器 PHP-FPM_阿喵看海外的博客
php-fpm是PHP的一個進程管理器。php下面的眾多work進程皆有php-fpm進程管理器管理。 php-fpm的工作原理 php-fpm全名是PHP FastCGI進程管理器。php-fpm啟動後會先讀php.ini,然後再讀相應的conf配置文件,conf配置可以覆蓋php.ini的配置。
繼續訪問
php-fpm解讀-進程管理的三種模式_april2nd的博客_php-fpm...
php-fpm進程管理一共有三種模式:ondemand、static、dynamic,我們可以在同一個fpm的master配置三種模式,看下圖1。php-fpm的工作模式和nginx類似,都是一個master,多個worker模型。每個worker都在accept本pool內的監聽套接字(linux已不存在驚...
繼續訪問
淺談PHP進程管理
這篇文章是對之前一篇文章的補充和改進, 創建一個主(master)進程,主進程安裝定時器,每隔5分鍾檢測一次隊列長度,根據隊列長度計算需要的worker進程, 然後創建或者殺掉子進程。這樣做的好處是防止隊列堆積,任務得不到及時處理。更新業務代碼,只需要reload操作即可。 整個流程有以下知識點: 創建守護進程的步驟: 設置默認文件許可權 fork一個進程,父進程退出 調用setsid創建一個新的會話 將當前工作目錄更改為根目錄 關閉不再需要的文件描述符 使用信號實現定時器 上一篇定時器依賴於系統的定時任務,這次使用鬧鍾信號實現,php 5.3.0以下的版本依賴於ticks,
php 腳本 fpm緩存,PHP生命周期及fpm(FastCGI進程管理器)的運作方式
PHP在web方式中如何改了文件就立即生效的,重要的幾個概念:sapi: 可以簡單的理解為php引擎對外的一個統一介面,使得php可以和外部程序進行交互php的生命周期中關鍵四個調用: MINT -> RINT -> RSHUTDOWN -> MSHUTDOWNfpm: fastcgi進程管理器fpm方式的流程就是:fpm通過sapi介面與php進程交互1.fpm啟動會調用各擴展...
繼續訪問
Linux下搭建PHP開發環境,Php-Fpm進程管理。_黑夜開發者的博客
目前PHP項目開發幾種比較流行的架構搭建中,LNMP在性能方面是最好的,正因為如此,使得LNMP架構逐漸流行起來,今天,前面提到了Nginx部署,由於項目實際環境的需要,今天就在說一下怎麼部署PHP。 環境 ...
繼續訪問
php而為,為高負載而生的 PHP 進程管理器 —— PHP-PM (PPM)
PHP-PM 可以用於php應用程序的進程管理,增壓和負載均衡.它使用 ReactPHP 實現php的事件驅動和非阻塞I/O。 它是基於 ReactPHP,最好是工作在基於請求-響應式的框架,像Symfony的HTTPKernel。這樣做是為了減少php啟動(包括變數聲明,載入和...
繼續訪問
最新發布 php進程管理
php 進程管理 tasks 過多
繼續訪問
PHP進程實現&管理
運行環境為Linux,模式為CLI DEMO /*要創建的子進程*/ $manager = [ 'work1', 'work2', 'work3', ]; /*當前進程名稱*/ $status = file_exists('/proc/' . getmypid() . '/status'); $bash = '-'; if ($status) { $bash = file('/proc/' . getmypid() . '/status', FILE_IGNORE.
繼續訪問
php的管理進程管理利器--php-fpm_weixin_33778778的博客
mod_php 模式是將php模塊安裝到apache中,所以每一次apache結束的請求呢,都會產生一條進程,這個進程就完整的包括php的各種運算計算等操作。 從圖中我們很清晰的可以看到,apache每接收一個請求,都會產生一個進程來連接php通過sapi來完成請求...
繼續訪問
php-frm進程管理,PHP內核探索-進程管理
進程管理方式首先我們了解一下php的三種不同的進程管理方式:static:靜態管理進程。在啟動時,master按照pm.max_children配置fork出對應數量的work進程,即work的進程是固定不變的。dynamic:動態管理進程。在fpm啟動時先按照pm.start_servers初始化一定數量的work進程,運行期間如果master發現空閑work進程低於pm.min_spare_s...
繼續訪問
理解php-fpm的兩種執行方式
前段時間配置php-fpm的時候,無意間發現原來他還有兩種執行方式。與Apache一樣,他的進程數也是可以根據設置分為動態和靜態的。關於Apache的工作方式及對應的設置方法,我已經在《Ubuntu下配置Apache的Worker模式》一文中寫出,這里不再多說。 而php-fpm也是同樣存在兩種方式,一種是直接開啟指定數量的php-fpm進程,不再增加或者減少;另一...
繼續訪問
php進程原理_PHP進程管理器php-fpm的工作原理
PHP進程管理器php-fpm的工作原理發布時間:2020-07-21 17:46:39來源:億速雲閱讀:133作者:小新今天小編給大家分享的是PHP進程管理器php-fpm的工作原理,相信很多人都不太了解,為了讓大家更加了解,所以給大家總結了以下內容,一起往下看吧。一定會有所收獲的哦。php-fpm是什麼php-fpm是PHP的一個進程管理器。php下面的眾多work進程皆有php-fpm進程管...
繼續訪問
如何管理php常駐進程,一看就懂系列之 如何實現與控制php常駐進程-Go語言中文社區...
前言關於如何實現與控制php常駐進程,不管是google還是上進行搜索,都沒有感覺看起來賞心悅目的解答,於是決定自己動手總結下。有同學會問了,整這個干甚?簡單的說就是,可以讓一個php腳本一直處於運行的狀態。從而實現將項目中某些耗時操作非同步化,進隊列後由php腳本取出再執行。有同學又會問了,直接在伺服器直接命令「php test.php &」,不就可以實現了?那麼這樣做的話有三點...
繼續訪問
PHP-FPM(PHP進程管理器)
PHP-FPM
繼續訪問
php 進程管理,從 0 到 1 優雅的實現 PHP 多進程管理
_| |_ __ __ _ _ __ _ _| |_ ___| '_ \ / _` | '__| | | | __/ _ \| | | | (_| | | | |_| | || (_) ||_| |_|\__,_|_| \__,_|\__\___/ .TIGERB.cnAn object-oriented multi process manager for PHPVersion: 0...
繼續訪問
php-fpm進程管理的三種模式
轉載自 php-fpm解讀-進程管理的三種模式 —程序媛大麗 標明轉載以示尊重 感謝原作者的分享。 php-fpm進程管理一共有三種模式:ondemand、static、dynamic,我們可以在同一個fpm的master配置三種模式,看下圖1。php-fpm的工作模式和nginx類似,都是一個master,多個worker模型。每個worker都在accept本pool內的監聽套接字(linu...
繼續訪問
php 進程管理那點事
之前本地開發和環境一直用的集成環境,最近新項目 集成了php7+nginx 跑了一段時間發現偶爾 有php進程退出的情況 排查原因 nginx log: 1111 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after ...
繼續訪問
從0到1優雅的實現PHP多進程管理
_ | | _ __ __ _ _ __ _ _| |_ ___ | '_ \ / _` | '__| | | | __/ _ \ | | | | (_| | | | |_| | || (_) | |_| |_|\__,_|_| \__,_|\__\___/ ...
繼續訪問
熱門推薦 php-fpm安裝、配置與優化
轉載自:https://www.zybuluo.com/phper/note/89081 1、php中fastcgi和php-fpm是什麼東西 最近在研究和學習php的性能方面的知識,看到了factcgi以及php-fpm,發現我對他們是少之又少的理解,可以說幾乎是一無所知,想想還是蠻可怕的。決定仔細的學習一下關於這方面的知識。 參考和學習了以下文章: 1. mod_php和
繼續訪問
php-fpm的兩種進程管理模式
php-fpm的兩種進程管理模式 php-fpm的進程數也是可以根據設置分為動態和靜態的。 一種是直接開啟指定數量的php-fpm進程,不再增加或者減少; 另一種則是開始的時候開啟一定數量的php-fpm進程,當請求量變大的時候,動態的增加php-fpm進程數到上限,當空閑的時候自動釋放空閑的進程數到一個下限。 這兩種不同的執行方式,可以根據伺服器的實際需求來進行調整。 這里先說一下涉及
繼續訪問
7、Php-Fpm進程管理
1、進程管理 php-fpm採用的是master-worker的進程方式。其中, master負責監聽埠,等待鏈接;其次,注冊信號,可以通過信息好master進行管理 worker負責處理具體的邏輯 如下圖所示 2、信號管理 master進程可以理解如下信號 信號 含義 INT, TERM 立刻終止 ...
繼續訪問
php進程式控制制
簡介 PHP的進程式控制制支持實現了Unix方式的進程創建, 程序執行, 信號處理以及進程的中斷。 進程式控制制不能被應用在Web伺服器環境,當其被用於Web服務環境時可能會帶來意外的結果。 這份文檔用於闡述每個進程式控制制函數的通常用法。關於Unix進程式控制制的更多信息建議您查閱 系統文檔中關於fork(2),waitpid(2),signal(2)等的部分或更全面的參考資料比如 《Unix環境高級編程》
繼續訪問
php進程管理
php 進程管理
② php發送郵件代碼要最新的網上試了很多都不成功
親,很高興為你解答:
首先,在PHP中可以使用SMTP或內置mail()函數來發送郵件。前者的好處是投遞率高、被認定為垃圾郵件的幾率小、但需要有SMTP伺服器;後者是無需配置,但極易被認定為垃圾郵件。
第一種方法:SMTP:
增加一個SMTP類,命名為class.smtp.php:
<?php
classsmtp
{
/*PublicVariables*/
var$smtp_port;
var$time_out;
var$host_name;
var$log_file;
var$relay_host;
var$debug;
var$auth;
var$user;
var$pass;
/*PrivateVariables*/
var$sock;
/*Constractor*/
functionsmtp($relay_host="",$smtp_port=25,$auth=false,$user,$pass)
{
$this->debug=FALSE;
$this->smtp_port=$smtp_port;
$this->relay_host=$relay_host;
$this->time_out=30;//isusedinfsockopen()
$this->auth=$auth;//auth
$this->user=$user;
$this->pass=$pass;
$this->host_name="localhost";//isusedinHELOcommand
$this->log_file="";
$this->sock=FALSE;
}
/*MainFunction*/
functionsendmail($to,$from,$subject="",$body="",$mailtype,$cc="",$bcc="",$additional_headers="")
{
$mail_from=$this->get_address($this->strip_comment($from));
$body=ereg_replace("(^|( ))(.)","1.3",$body);
$header.="MIME-Version:1.0 ";
if($mailtype=="HTML")
{
$header.="Content-Type:text/html ";
}
$header.="To:".$to." ";
if($cc!="")
{
$header.="Cc:".$cc." ";
}
$header.="From:$from<".$from."> ";
$header.="Subject:".$subject." ";
$header.=$additional_headers;
$header.="Date:".date("r")." ";
$header.="X-Mailer:ByRedhat(PHP/".phpversion().") ";
list($msec,$sec)=explode("",microtime());
$header.="Message-ID:<".date("YmdHis",$sec).".".($msec*1000000).".".$mail_from."> ";
$TO=explode(",",$this->strip_comment($to));
if($cc!="")
{
$TO=array_merge($TO,explode(",",$this->strip_comment($cc)));
}
if($bcc!="")
{
$TO=array_merge($TO,explode(",",$this->strip_comment($bcc)));
}
$sent=TRUE;
foreach($TOas$rcpt_to)
{
$rcpt_to=$this->get_address($rcpt_to);
if(!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error:Cannotsendemailto".$rcpt_to." ");
$sent=FALSE;
continue;
}
if($this->smtp_send($this->host_name,$mail_from,$rcpt_to,$header,$body))
{
$this->log_write("E-mailhasbeensentto<".$rcpt_to."> ");
}
else
{
$this->log_write("Error:Cannotsendemailto<".$rcpt_to."> ");
$sent=FALSE;
}
fclose($this->sock);
$this->log_write("Disconnectedfromremotehost ");
}
return$sent;
}
/*PrivateFunctions*/
functionsmtp_send($helo,$from,$to,$header,$body="")
{
if(!$this->smtp_putcmd("HELO",$helo))
{
return$this->smtp_error("sendingHELOcommand");
}
#auth
if($this->auth)
{
if(!$this->smtp_putcmd("AUTHLOGIN",base64_encode($this->user)))
{
return$this->smtp_error("sendingHELOcommand");
}
if(!$this->smtp_putcmd("",base64_encode($this->pass)))
{
return$this->smtp_error("sendingHELOcommand");
}
}
if(!$this->smtp_putcmd("MAIL","FROM:<".$from.">"))
{
return$this->smtp_error("sendingMAILFROMcommand");
}
if(!$this->smtp_putcmd("RCPT","TO:<".$to.">"))
{
return$this->smtp_error("sendingRCPTTOcommand");
}
if(!$this->smtp_putcmd("DATA"))
{
return$this->smtp_error("sendingDATAcommand");
}
if(!$this->smtp_message($header,$body))
{
return$this->smtp_error("sendingmessage");
}
if(!$this->smtp_eom())
{
return$this->smtp_error("sending<CR><LF>.<CR><LF>[EOM]");
}
if(!$this->smtp_putcmd("QUIT"))
{
return$this->smtp_error("sendingQUITcommand");
}
returnTRUE;
}
functionsmtp_sockopen($address)
{
if($this->relay_host=="")
{
return$this->smtp_sockopen_mx($address);
}
else
{
return$this->smtp_sockopen_relay();
}
}
functionsmtp_sockopen_relay()
{
$this->log_write("Tryingto".$this->relay_host.":".$this->smtp_port." ");
$this->sock=@fsockopen($this->relay_host,$this->smtp_port,$errno,$errstr,$this->time_out);
if(!($this->sock&&$this->smtp_ok()))
{
$this->log_write("Error:Cannotconnencttorelayhost".$this->relay_host." ");
$this->log_write("Error:".$errstr."(".$errno.") ");
returnFALSE;
}
$this->log_write("Connectedtorelayhost".$this->relay_host." ");
returnTRUE;;
}
functionsmtp_sockopen_mx($address)
{
$domain=ereg_replace("^.+@([^@]+)$","1",$address);
if(!@getmxrr($domain,$MXHOSTS))
{
$this->log_write("Error:CannotresolveMX"".$domain."" ");
returnFALSE;
}
foreach($MXHOSTSas$host)
{
$this->log_write("Tryingto".$host.":".$this->smtp_port." ");
$this->sock=@fsockopen($host,$this->smtp_port,$errno,$errstr,$this->time_out);
if(!($this->sock&&$this->smtp_ok()))
{
$this->log_write("Warning:Cannotconnecttomxhost".$host." ");
$this->log_write("Error:".$errstr."(".$errno.") ");
continue;
}
$this->log_write("Connectedtomxhost".$host." ");
returnTRUE;
}
$this->log_write("Error:Cannotconnecttoanymxhosts(".implode(",",$MXHOSTS).") ");
returnFALSE;
}
functionsmtp_message($header,$body)
{
fputs($this->sock,$header." ".$body);
$this->smtp_debug(">".str_replace(" "," ".">",$header." >".$body." >"));
returnTRUE;
}
functionsmtp_eom()
{
fputs($this->sock," . ");
$this->smtp_debug(".[EOM] ");
return$this->smtp_ok();
}
functionsmtp_ok()
{
$response=str_replace(" ","",fgets($this->sock,512));
$this->smtp_debug($response." ");
if(!ereg("^[23]",$response))
{
fputs($this->sock,"QUIT ");
fgets($this->sock,512);
$this->log_write("Error:Remotehostreturned"".$response."" ");
returnFALSE;
}
returnTRUE;
}
functionsmtp_putcmd($cmd,$arg="")
{
if($arg!="")
{
if($cmd=="")
{
$cmd=$arg;
}
else
{
$cmd=$cmd."".$arg;
}
}
fputs($this->sock,$cmd." ");
$this->smtp_debug(">".$cmd." ");
return$this->smtp_ok();
}
functionsmtp_error($string)
{
$this->log_write("Error:Erroroccurredwhile".$string.". ");
returnFALSE;
}
functionlog_write($message)
{
$this->smtp_debug($message);
if($this->log_file=="")
{
returnTRUE;
}
$message=date("MdH:i:s").get_current_user()."[".getmypid()."]:".$message;
if(!@file_exists($this->log_file)||!($fp=@fopen($this->log_file,"a")))
{
$this->smtp_debug("Warning:Cannotopenlogfile"".$this->log_file."" ");
returnFALSE;;
}
flock($fp,LOCK_EX);
fputs($fp,$message);
fclose($fp);
returnTRUE;
}
functionstrip_comment($address)
{
$comment="([^()]*)";
while(ereg($comment,$address))
{
$address=ereg_replace($comment,"",$address);
}
return$address;
}
functionget_address($address)
{
$address=ereg_replace("([ ])+","",$address);
$address=ereg_replace("^.*<(.+)>.*$","1",$address);
return$address;
}
functionsmtp_debug($message)
{
if($this->debug)
{
echo$message;
}
}
}
?>
然後在PHP裡面引用該文件後,這樣調用發送郵件:
<?php
require_once("class.smtp.php");
$smtpserver="";//SMTP伺服器
$smtpserverport=25;//SMTP伺服器埠
$smtpusermail="";//SMTP伺服器的用戶郵箱
$smtpemailto="";//發送給誰
$smtpuser="";//SMTP伺服器的用戶帳號
$smtppass="";//SMTP伺服器的用戶密碼
$mailsubject="";//郵件主題
$mailbody="";//郵件內容
$mailtype="HTML";//郵件格式(HTML/TXT)
$smtp=newsmtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//這裡面的一個true是表示使用身份驗證,否則不使用身份驗證
$smtp->debug=TRUE;//是否顯示發送的調試信息
$smtp->sendmail($smtpemailto,$smtpusermail,$mailsubject,$mailbody,$mailtype);
?>
第二種方法:mail()函數
<?php
$to="[email protected],[email protected]";
$subject="HTMLemail";
$message="
<html>
<head>
<title>HTMLemail</title>
</head>
<body>
<p>ThisemailcontainsHTMLTags!</p>
</body>
</html>
";
$headers="MIME-Version:1.0"." ";
$headers.="Content-type:text/html;charset=iso-8859-1"." ";
//其他報頭
$headers.='From:<[email protected]>'." ";
$headers.='Cc:[email protected]'." ";
mail($to,$subject,$message,$headers);
?>
-----------------------------------
如有疑問歡迎追問!
滿意請點擊右上方【選為滿意回答】按鈕 o(∩_∩)o
③ PHP中發送郵件的代碼!
從代碼來看,想必樓主是想把表單提交的內容發送至指定郵箱,而這個郵箱地址也是在表單中填寫的,$sendTo變數的值被賦為表單項「toMail」傳過來的值。
如此,你可以在填寫表單的時候在toMail表單項里填入「[email protected]」,或者直接$sendTo="[email protected]"。
接下來就要考慮是否能發送出去了:
1、如果樓主配置的伺服器安裝了sendmail組件,就可以直接使用你寫的這段代碼來完成任務。
2、如果沒有安裝sendmail組件,就要接用smtp伺服器來發送了。這樣相對較復雜,要引用一個PHP類。具體代碼如下:
SMTP.PHP:
<?php
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* Private Variables */
var $sock;
/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header = "MIME-Version:1.0\r\n";
if($mailtype=="HTML")
{
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "")
{
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to)
{
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else
{
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo))
{
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user)))
{
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{
return $this->smtp_error("sending HELO command");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom())
{
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "")
{
return $this->smtp_sockopen_mx($address);
}
else
{
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS))
{
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host)
{
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
$cmd = $arg;
else
$cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))
{
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug)
{
echo $message;
}
}
}
?>
DEMO:TEST.PHP
<?php
require "smtp.php";
$smtpserver = "smtp.xxx.com";//SMTP伺服器
$smtpserverport =25;//SMTP伺服器埠
$smtpusermail = "[email protected]";//SMTP伺服器的用戶郵箱
$smtpemailto = "[email protected]";//發送給誰
$smtpuser = "xxxx";//SMTP伺服器的用戶帳號
$smtppass = "xxxx";//SMTP伺服器的用戶密碼
$mailsubject = "客戶反饋意見!";//郵件主題
$mailbody = "<h1>這是我的一個測試~~~</h1>";//郵件內容
$mailtype = "HTML";//郵件格式(HTML/TXT),TXT為文本郵件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//這裡面的一個true是表示使用身份驗證,否則不使用身份驗證.
$smtp->debug = false;//是否顯示發送的調試信息
$return = ($smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype));
echo $return;
?>
④ 如何獲知PHP程序佔用多少內存memory
<?php
header("Content-type:text/html;charset=utf-8");
//獲取當前運行腳本佔用內存
functiongetMemeoryByScript(){
//首先判斷系統是否支持memory_get_usage函數
if(function_exists('memory_get_usage')){
returnmemory_get_usage();
}else{
$pid=getmypid();
//判斷是否為Windows伺服器
if(strtoupper(substr(PHP_OS,0,3))==='WIN'){
//命令查詢pid所佔的內存
exec('tasklist/FI"PIDeq'.$pid.'"/FO渣肢LIST',$output);
判梁亮//取出數字,然後轉換為M(默認結果為k)
returnpreg_replace('/[^0-9]/','',$output[5])*1024;
}else{
exec("ps-eo%mem,rss,pid|grep$pid",$output);
$output=explode("",$output[0]);
掘寬return$output[1]*1024;
}
}
}
echogetMemeoryByScript();
//325288
?>
⑤ php表單提交到郵箱怎麼做到
index.php
<?php
$stm="郵件內容";
require("smtp.php");
##########################################
$smtpserver = "mail.chg168.com";//SMTP伺服器
$smtpserverport = 25;//SMTP伺服器埠
$smtpusermail = "[email protected]";//SMTP伺服器的用戶郵箱
$smtpemailto = "[email protected]";//發送給誰
$smtpuser = "[email protected]";//SMTP伺服器的用戶帳號
$smtppass = "111111";//SMTP伺服器的用戶密碼
$mailsubject = "dddddddddddd ";//郵件主題
$mailbody = $stm;//郵件內容
$mailtype = "HTML";//郵件格式(HTML/TXT),TXT為文本郵件
##########################################
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//這裡面的一個true是表示使用身份驗證,否則不使用身份驗證.
$smtp->debug = TRUE;//是否顯示發送的調試信息
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
echo "<script>alert('郵件發送成功');parent.document.ADDUser.cheheh.click();</script>";
exit;
}
?>
smtp.php
<?php
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* Private Variables */
var $sock;
/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML")
{
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "")
{
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to)
{
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else
{
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo))
{
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user)))
{
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom())
{
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "")
{
return $this->smtp_sockopen_mx($address);
}
else
{
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS))
{
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host)
{
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
{
$cmd = $arg;
}
else
{
$cmd = $cmd." ".$arg;
}
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))
{
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug)
{
//echo $message;
}
}
}
?>
我測試過的哈 自己的網站也是用的這個 絕對沒有問題哈,你可以入群29077119 裡面有這方面的高手哈
⑥ php 中getmypid()函數被禁用,有其他替換函數嗎
php 中getmypid()函數被禁用,可以用getmyuid() get_current_user() getmyinode() getlastmod()替代。
php中getmypid函數的用法:
含義:返世閉手回 PHP 的行程代號。
語法: int getmypid(void);
返回值: 整數
函數種類: PHP 系統功態拍能
內容說明: 本函數返回搜嫌 PHP 的行程代號值 (PID)。若執行失敗則返回 false 值。當 PHP 以 Apache 模塊存在時,返回的 PID 值不見得是正確的。
參考: getmyuid() get_current_user() getmyinode() getlastmod()
⑦ 如何使用php的mail函數
可以,但是這要需要smtp.163.com的用戶名與密碼
我給你一個郵件發送類,你可以直接用
/*
名稱:smtpsend.class.php
功能:郵件發送類,實現郵件發送功能 ,可以發送html郵件;可驗證用戶是否具有發送許可權;可實現從任意伺服器郵箱發送郵件,並非局限於本機。
時間:2008-03
author:三生石
$smtpserver; SMTP伺服器
$smtpserverport; SMTP伺服器埠
$smtpuser; SMTP伺服器的用戶帳號
$smtppass; SMTP伺服器的用戶密碼
$fromMail; SMTP伺服器的用戶郵箱
$toMail; 發送給誰
$subject; 郵件主題
$content; 郵件內容
$mailtype; 郵件格式(HTML/TXT),TXT為文本郵件
*/
class smtpclass
{
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 60; //is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $returnpath = "", $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header = "";
if(isset($returnpath) && $returnpath != "")
{
$header .= "Reply-To:".$returnpath."\r\n";
}
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= 'Content-Type:text/html; charset=gb2312' . "\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
} else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug) {
echo $message;
}
}
function senserMail($smtpserver,$smtpserverport=25,$smtpuser,$smtppass,$fromMail,$toMail,$subject,$content,$mailtype='HTML')
{
if ($fromMail == "") {
die("發件人不能為空!");
}
if ($smtpuser == "") {
die("用戶名不能為空!");
}
if ($smtppass == "") {
die("用戶密碼不能為空!");
}
if ($subject == "") {
die("標題不能為空!");
}
if ($toMail == "") {
die("收件人不能為空!");
}
if ($content == "") {
die("內容不能為空!");
}
$smtpserver = $smtpserver;//SMTP伺服器
$smtpserverport = $smtpserverport;//SMTP伺服器埠
$smtpuser = $smtpuser;//SMTP伺服器的用戶帳號
$smtppass = $smtppass;//SMTP伺服器的用戶密碼
$smtpusermail = $fromMail;//SMTP伺服器的用戶郵箱
$smtpemailto = $toMail;//發送給誰
$mailsubject = $subject;//郵件主題
$mailbody = $content;//郵件內容
$mailtype = $mailtype;//郵件格式(HTML/TXT),TXT為文本郵件
$this->smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//這裡面的一個true是表示使用身份驗證,否則不使用身份驗證.
//$smtp->debug = TRUE;//是否顯示發送的調試信息
$this->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
}
}
//$gao = new smtpclass();
//$gao->senserMail("mail.163.com",25,"用戶名","密碼","[email protected]","[email protected]","測試","測試一下","TXT");
⑧ PHP 中怎樣終止單個進程
<?php
exec("kill-9pid,$op,$status);
?>
把結果逐行追加到$op的結尾處,只有指定了第二 個參數時,才可以用第三個參數,用來取得命令執行的狀態碼。$status 1 kill成功,0 是失敗(一般情況下是無此進程)。
我的實際項目中是在執行的開始通過getmypid()獲取進程id保存到資料庫,如果crontab再次觸發則把之前的進程kill掉再重新執行一遍以上代碼。
希望能幫到你。
⑨ php中,posix_getpid() 和 getmypid() 有什麼不同
posix_getpid()是「返回返回返回」謹者當祥兄薯前進程 id,返回值須是整型塵納。
getmypid()是獲取 PHP 進程的 ID。
⑩ php getmypid獲得的pid與操作系統中看到的pid不一致
本函數(getmypid)返回 PHP 的行程代號漏空液值 (PID)。返物若執行失敗則返回 false 值。當 PHP 以 Apache 模塊存在時虧液,返回的 PID 值不見得是正確的。