Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Optymalizacja skryptu.
Forum PHP.pl > Forum > Gotowe rozwiązania
outlawReg
No to więc czy wie może ktoś dlaczego caly ten skrypt chodzi tak wolno:
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE); 
  3. class MailSmtp{
  4.  
  5. var $host;
  6. var $port;
  7. var $loginUsr;
  8. var $pass;
  9.  
  10. /**
  11. * SMTP server port
  12. * @var int
  13. */
  14. var $defport = 25;
  15.  
  16. /** 
  17. * Timeout socket
  18. * @var int
  19. */
  20. var $deftimeout = 10;
  21.  
  22. /**#@+
  23. * @access private
  24. */
  25. var $timeout;
  26. var $error;
  27. var $socket;
  28. var $debug;
  29. var $tmp;
  30. /**#@-*/
  31.  
  32. function MailSmtp($host, $port = '', $login = '', $pass = '', $timeout = ''){
  33. $this -> host  = $host;
  34. $this -> loginUsr  = $login;
  35. $this -> pass = $pass;
  36.  
  37. if (empty($port)){
  38. $this -> port = $this -> defport;
  39. } else {
  40. $this -> port = $port;
  41. }
  42.  
  43. if (empty($timeout)){
  44. $this -> timeout = $this -> deftimeout;  
  45. } else {
  46. $this -> timeout = $timeout;
  47. } 
  48. $this -> debug = 1;
  49. $this -> error = null;
  50. $this -> socket = 0;
  51. }
  52.  
  53. function Connect(){
  54.  
  55. $errno  =''; 
  56. $errstr ='';
  57.  
  58.  
  59.  
  60. if ($this -> Connected()){
  61. $error = $this -> Error(5);
  62. echo 'MailSmtp -> ERROR: '.$error;
  63. }
  64.  
  65. $this -> socket = fsockopen($this -> host, $this -> port, $errno, $errstr, $this -> timeout);
  66. if (empty($this -> socket)){
  67. $this -> error = array('error'=> $this -> Error(6),'errno' => $errno, 'errstr' => $errstr);
  68.  
  69. if ($this -> debug >= 1){
  70.  echo 'MailSmtp -> ERROR: '.$this -> error['error'].':'.$this -> error['errno'].'rn';
  71. }
  72. return false;
  73. }
  74.  
  75. if (substr(PHP_OS,0,3) != 'WIN'){
  76. socket_set_timeout($this -> socket,$this -> timeout,$this -> timeout);
  77.  
  78. }
  79.  
  80.  
  81. echo $this -> get();
  82. $smtp['ehlo'] = "EHLO rn";
  83. $smtp['helo'] = "HELO $this -> host rn";
  84.  
  85. if (!empty($this -> loginUsr) && !empty($this -> pass)){
  86. $this -> cmd($smtp['ehlo']);
  87. $this -> Login();
  88. } else {
  89. $this -> cmd($smtp['helo']);
  90. }
  91.  
  92.  
  93. return true;
  94.  
  95. }
  96.  
  97. function Connected(){
  98. if(!empty($this -> socket)){
  99. $sock = socket_get_status($this -> socket);
  100. if ($sock['eof']){
  101. $this -> close();
  102. return false;
  103. }
  104. return true;
  105. }
  106. return false;
  107. }
  108.  
  109. function Login($type = 'LOGIN'){
  110.  
  111. $login  = $this -> loginUsr;
  112. $login2 = $this -> loginUsr;
  113. $pass = $this -> pass;
  114. $smtp['auth'] = "AUTH LOGIN rn";
  115. $smtp['authplain'] = "AUTH PLAIN rn";
  116.  
  117. if ($type == 'LOGIN'){
  118. $this -> cmd($smtp['auth']);
  119. $this -> cmd(base64_encode($login)."rn");
  120. $this -> cmd(base64_encode($pass)."rn");
  121. } elseif ($type == 'PLAIN'){
  122. //Jescze nie ma :)
  123. }
  124.  
  125.  
  126. }
  127.  
  128. function sendmail($from, $to, $subject, $message){
  129.  
  130.  
  131. //Nadawca listu
  132. $this->cmd("MAIL FROM:<".$from.">rn");
  133. //Odbiorca listu
  134. $this->cmd("RCPT TO:<".$to.">rn");
  135. //Wysyłanie data
  136. $this->cmd("DATArn");
  137. #$smtp['auth'] = "AUTH LOGIN rn";
  138. #$this -> cmd($smtp['auth']);
  139.  
  140.  /* temat wiadomosci */
  141.  $this->cmd("Subject: ".$subject."rn");
  142.  
  143.  /* kodowanie */
  144.  $this->cmd("Content-type: text/html; charset=iso-8859-2rn");
  145.  
  146.  /* naglowki */
  147.  $this->cmd("From: ".$from."rn");
  148. $this->cmd("Reply-To: ".$from."rn");
  149.  $this->cmd("Return-Path: ".$from."rnrn");
  150.  
  151.  /* tresc wiadomosci */
  152.  $this->cmd($message."rn");
  153.  $this->cmd(".rn"); // koniec wiadomosci
  154.  
  155. }
  156.  
  157. function cmd($msg){
  158.  if (fwrite($this -> socket,$msg) > 0){
  159. $get = $this -> get();
  160. if ($this -> debug >= 1){
  161.  echo $get;
  162. }
  163.  $this -> tmp = substr($get,0,3);
  164.  if ($this -> tmp >= 211 and $this -> tmp <= 400){
  165.  return true;
  166.  } elseif ($this -> tmp > 400){
  167.  return false;
  168.  }
  169.  
  170.  } else {
  171.  if ($this -> debug >= 1){
  172.  echo 'ERROR -> CMD:'.$this -> Error(7).':'.$get;
  173.  }
  174.  return false;
  175.  }
  176. }
  177.  
  178. function get(){
  179. $data = '';
  180. while ($str = fgets($this -> socket,515)) {
  181.  
  182. if(substr($str,3,1) === ' ') 
  183. { 
  184. $data .= $str.'</br>';
  185. break 1; 
  186. } else {
  187. $data .= $str.'</br>';
  188. }
  189. }
  190. return $data;
  191. }
  192.  
  193. function Disconnect(){
  194.  
  195. $this -> cmd("QUIT");
  196. @fclose($this -> socket);
  197. $this -> socket = 0;
  198.  
  199.  
  200. }
  201.  
  202. function close(){
  203. $this -> error = null;
  204.  
  205. if(!empty($this -> socket)){
  206. @fclose($this -> socket);
  207. $this -> socket = 0;
  208. }
  209.  
  210. }
  211.  
  212. function Error($num, $msg='')
  213.  {
  214.  switch ($num){
  215.  case 5:  return 'Już jesteś połonczony'; 
  216.  case 6:  return 'Nie można sie połonczyć';
  217.  case 7: return 'Nie można wysłać do serwera';
  218.  case 211: return 'HELP: '.$msg;  
  219.  case 214: return 'Komunikat pomocy dla użytkownika'.$msg; 
  220.  case 220: return 'Informacje o gotowości usługi.'; 
  221.  case 221: return 'Zamykanie połonczenia.'; 
  222.  case 250: return 'Powodzenie żądanej operacji.'; 
  223.  case 251: return 'Użytkownik nie odnaleziony, przekazywanie na adres '.$msg; 
  224.  case 345: return; 
  225.  case 421: return; 
  226.  case 450: return; 
  227.  case 451: return; 
  228.  case 452: return;
  229.  case 500: return 'Polecenie nie zostało rozpoznane lub ma niepoprawną składnię.';
  230.  case 501: return 'Błąd w składni parametrów lub opcji polecenia'; 
  231.  case 502: return 'Polecenie nie obsługiwane'; 
  232.  case 503: return 'Niewłaściwa kolejność przesyłanych poleceń.'; 
  233.  case 504: return 'Parametr polecenia nie jest obsługiwany.'; 
  234.  case 550: return; 
  235.  case 551: return; 
  236.  case 552: return; 
  237.  case 553: return; 
  238.  case 554: return; 
  239.  
  240.  }
  241.  }
  242.  
  243.  
  244.  
  245. }
  246.  
  247. $mail = new MailSmtp('mail.praca-pl.com',25,'hands@praca-pl.com','*****');
  248. $mail -> Connect();
  249. $mail -> sendmail('hands@praca-pl.com','outlawreg@gmail.com','To jest temat wiadomośći','A tu jest treść wiadomości');
  250. $mail -> Disconnect();
  251.  
  252. ?>


Cały ten skrypt wykonuje się na serwerze api_smtp.php
borec
moze to nie skrypt tylko serwer z ktorym skrypt sie laczy?
outlawReg
juz rozwiązałem wystarczy ze nie bedzie pobierało fgets to wtedy jest luzik wysyła maile jak lala biggrin.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.