Re: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread Tom Rogers
Hi,

Saturday, September 3, 2005, 9:19:11 AM, you wrote:
MS hello,

MS I'm writing a socket approach to send email directly via an SMTP server
MS (since some hosts block sendmail trough php due to abuse). Now, I have
MS the code, attached below:
MS I have cut it down slightly so it would still be readable though. I'm
MS very sure that none of the stuff I removed actually matters in the
MS problem though (mostly error chechking, logging, debug stuff, etc).

MS Ok, back to the problem. If I reread my log, I see the following output:
MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
MS C: HELO ip
MS S:
MS C: MAIL FROM: [EMAIL PROTECTED]
MS S: 250 server OK, server2 [ip].
MS C: RCPT TO: [EMAIL PROTECTED]
MS S:
MS C: RSET

MS Now, obviously, the server sends something back (I checked, manually,
MS using telnet). So, I figured that the socket_read(socket, size, 
MS PHP_NORMAL_READ) was causing the problem. So I switched over to 
MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke
MS off eg. midways). So... after I changed that, I suddenly started getting
MS these errors:
MS Warning: socket_read() unable to read from socket [11]: Resource 
MS temporarily unavailable in /home/me/scripts/mail.php on line 27

MS This goes for each attempt to read (even the first). I'm stumped... and
MS really don't know how to proceed now...

MS Does anyone have any clues?
MS very appreciated,

Because of this line the function returns straight away.

MS socket_set_nonblock($this-socket);

You have to catch the 'not ready' error something like this:
(The error code was under windows)

function get(){
  $ret = '';
  while(1){
$sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ);
if(false === $sbuf){
  $error = socket_last_error($this-connection);
  if($error != 10035){
echo msgsock read() failed: reason:  .$error.' '. socket_strerror 
(socket_last_error($this-connection)) . \n;
return;//socket not happy
  }
}else{
  $buf_read = strlen($sbuf);
  if($buf_read === 0) break; // end of text
  $ret .= $sbuf;
}
  }
  return $ret;
}





-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread M. Sokolewicz

hello,

thank you for the help, but I've tried your code, and it returns the 
exact same thing :( the error #11 temporarily unavailable. If I remove 
non-blocking, or change the error to ignore to 11 (10035 in your code 
example) it simply hangs doing nothing *at all*...


I'm stumped; really.. thank you for trying though :)

- tul
Tom Rogers wrote:

Hi,

Saturday, September 3, 2005, 9:19:11 AM, you wrote:
MS hello,

MS I'm writing a socket approach to send email directly via an SMTP server
MS (since some hosts block sendmail trough php due to abuse). Now, I have
MS the code, attached below:
MS I have cut it down slightly so it would still be readable though. I'm
MS very sure that none of the stuff I removed actually matters in the
MS problem though (mostly error chechking, logging, debug stuff, etc).

MS Ok, back to the problem. If I reread my log, I see the following output:
MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
MS C: HELO ip
MS S:
MS C: MAIL FROM: [EMAIL PROTECTED]
MS S: 250 server OK, server2 [ip].
MS C: RCPT TO: [EMAIL PROTECTED]
MS S:
MS C: RSET

MS Now, obviously, the server sends something back (I checked, manually,
MS using telnet). So, I figured that the socket_read(socket, size, 
MS PHP_NORMAL_READ) was causing the problem. So I switched over to 
MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke

MS off eg. midways). So... after I changed that, I suddenly started getting
MS these errors:
MS Warning: socket_read() unable to read from socket [11]: Resource 
MS temporarily unavailable in /home/me/scripts/mail.php on line 27


MS This goes for each attempt to read (even the first). I'm stumped... and
MS really don't know how to proceed now...

MS Does anyone have any clues?
MS very appreciated,

Because of this line the function returns straight away.

MS  socket_set_nonblock($this-socket);

You have to catch the 'not ready' error something like this:
(The error code was under windows)

function get(){
  $ret = '';
  while(1){
$sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ);
if(false === $sbuf){
  $error = socket_last_error($this-connection);
  if($error != 10035){
echo msgsock read() failed: reason:  .$error.' '. socket_strerror 
(socket_last_error($this-connection)) . \n;
return;//socket not happy
  }
}else{
  $buf_read = strlen($sbuf);
  if($buf_read === 0) break; // end of text
  $ret .= $sbuf;
}
  }
  return $ret;
}







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread Gustav Wiberg

Hi there!

Can't it be anything with filepermissions? Just a clue...

/G
@varupiraten.se

- Original Message - 
From: M. Sokolewicz [EMAIL PROTECTED]

To: php-general@lists.php.net; Tom Rogers [EMAIL PROTECTED]
Sent: Saturday, September 03, 2005 10:49 AM
Subject: Re: [PHP] socket_read() trouble with PHP_BINARY_READ



hello,

thank you for the help, but I've tried your code, and it returns the exact 
same thing :( the error #11 temporarily unavailable. If I remove 
non-blocking, or change the error to ignore to 11 (10035 in your code 
example) it simply hangs doing nothing *at all*...


I'm stumped; really.. thank you for trying though :)

- tul
Tom Rogers wrote:

Hi,

Saturday, September 3, 2005, 9:19:11 AM, you wrote:
MS hello,

MS I'm writing a socket approach to send email directly via an SMTP 
server
MS (since some hosts block sendmail trough php due to abuse). Now, I 
have

MS the code, attached below:
MS I have cut it down slightly so it would still be readable though. I'm
MS very sure that none of the stuff I removed actually matters in the
MS problem though (mostly error chechking, logging, debug stuff, etc).

MS Ok, back to the problem. If I reread my log, I see the following 
output:

MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
MS C: HELO ip
MS S:
MS C: MAIL FROM: [EMAIL PROTECTED]
MS S: 250 server OK, server2 [ip].
MS C: RCPT TO: [EMAIL PROTECTED]
MS S:
MS C: RSET

MS Now, obviously, the server sends something back (I checked, manually,
MS using telnet). So, I figured that the socket_read(socket, size, MS 
PHP_NORMAL_READ) was causing the problem. So I switched over to MS 
PHP_BINARY_READ to make sure I didn't miss anything (because it broke
MS off eg. midways). So... after I changed that, I suddenly started 
getting

MS these errors:
MS Warning: socket_read() unable to read from socket [11]: Resource MS 
temporarily unavailable in /home/me/scripts/mail.php on line 27


MS This goes for each attempt to read (even the first). I'm stumped... 
and

MS really don't know how to proceed now...

MS Does anyone have any clues?
MS very appreciated,

Because of this line the function returns straight away.

MS socket_set_nonblock($this-socket);

You have to catch the 'not ready' error something like this:
(The error code was under windows)

function get(){
  $ret = '';
  while(1){
$sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ);
if(false === $sbuf){
  $error = socket_last_error($this-connection);
  if($error != 10035){
echo msgsock read() failed: reason:  .$error.' '. 
socket_strerror (socket_last_error($this-connection)) . \n;

return;//socket not happy
  }
}else{
  $buf_read = strlen($sbuf);
  if($buf_read === 0) break; // end of text
  $ret .= $sbuf;
}
  }
  return $ret;
}







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 2005-09-02




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread Tom Rogers
Hi,

Saturday, September 3, 2005, 6:49:54 PM, you wrote:
MS hello,

MS thank you for the help, but I've tried your code, and it returns the
MS exact same thing :( the error #11 temporarily unavailable. If I remove
MS non-blocking, or change the error to ignore to 11 (10035 in your code
MS example) it simply hangs doing nothing *at all*...

MS I'm stumped; really.. thank you for trying though :)

Looking at your code, in the functions you have $this-connection but
the class uses $this-socket. In your application it is better not to
use blocking I think.

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread M. Sokolewicz

file permissions on what? These are sockets :(

- tul

As the wise Gustav Wiberg [EMAIL PROTECTED] said:


Hi there!

Can't it be anything with filepermissions? Just a clue...

/G
@varupiraten.se

- Original Message - From: M. Sokolewicz [EMAIL PROTECTED]
To: php-general@lists.php.net; Tom Rogers [EMAIL PROTECTED]
Sent: Saturday, September 03, 2005 10:49 AM
Subject: Re: [PHP] socket_read() trouble with PHP_BINARY_READ



hello,

thank you for the help, but I've tried your code, and it returns the 
exact same thing :( the error #11 temporarily unavailable. If I 
remove non-blocking, or change the error to ignore to 11 (10035 in 
your code example) it simply hangs doing nothing *at all*...


I'm stumped; really.. thank you for trying though :)

- tul
Tom Rogers wrote:

Hi,

Saturday, September 3, 2005, 9:19:11 AM, you wrote:
MS hello,

MS I'm writing a socket approach to send email directly via an SMTP server
MS (since some hosts block sendmail trough php due to abuse). Now, I have
MS the code, attached below:
MS I have cut it down slightly so it would still be readable though. I'm
MS very sure that none of the stuff I removed actually matters in the
MS problem though (mostly error chechking, logging, debug stuff, etc).

MS Ok, back to the problem. If I reread my log, I see the 
following output:

MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
MS C: HELO ip
MS S:
MS C: MAIL FROM: [EMAIL PROTECTED]
MS S: 250 server OK, server2 [ip].
MS C: RCPT TO: [EMAIL PROTECTED]
MS S:
MS C: RSET

MS Now, obviously, the server sends something back (I checked, manually,
MS using telnet). So, I figured that the socket_read(socket, size, 
MS PHP_NORMAL_READ) was causing the problem. So I switched over to 
MS PHP_BINARY_READ to make sure I didn't miss anything (because it 
broke
MS off eg. midways). So... after I changed that, I suddenly 
started getting

MS these errors:
MS Warning: socket_read() unable to read from socket [11]: 
Resource MS temporarily unavailable in /home/me/scripts/mail.php 
on line 27


MS This goes for each attempt to read (even the first). I'm stumped... and
MS really don't know how to proceed now...

MS Does anyone have any clues?
MS very appreciated,

Because of this line the function returns straight away.

MS socket_set_nonblock($this-socket);

You have to catch the 'not ready' error something like this:
(The error code was under windows)

function get(){
  $ret = '';
  while(1){
$sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ);
if(false === $sbuf){
  $error = socket_last_error($this-connection);
  if($error != 10035){
echo msgsock read() failed: reason:  .$error.' '. 
socket_strerror (socket_last_error($this-connection)) . \n;

return;//socket not happy
  }
}else{
  $buf_read = strlen($sbuf);
  if($buf_read === 0) break; // end of text
  $ret .= $sbuf;
}
  }
  return $ret;
}







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 2005-09-02









--
Tularis
XMB Developer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread M. Sokolewicz
In the end I decided I'll just use the fsockopen(), feof(), fwrite, 
fread, etc. function-set instead (got the idea from PEAR's NET_Socket). 
And that seems to work just fine... too bad I couldn't get the low-level 
functions to work (still don't know why), but this works great...


thank you all for the help/support though!
- tul

M. Sokolewicz wrote:

file permissions on what? These are sockets :(

- tul

As the wise Gustav Wiberg [EMAIL PROTECTED] said:


Hi there!

Can't it be anything with filepermissions? Just a clue...

/G
@varupiraten.se

- Original Message - From: M. Sokolewicz [EMAIL PROTECTED]
To: php-general@lists.php.net; Tom Rogers [EMAIL PROTECTED]
Sent: Saturday, September 03, 2005 10:49 AM
Subject: Re: [PHP] socket_read() trouble with PHP_BINARY_READ



hello,

thank you for the help, but I've tried your code, and it returns the 
exact same thing :( the error #11 temporarily unavailable. If I 
remove non-blocking, or change the error to ignore to 11 (10035 in 
your code example) it simply hangs doing nothing *at all*...


I'm stumped; really.. thank you for trying though :)

- tul
Tom Rogers wrote:


Hi,

Saturday, September 3, 2005, 9:19:11 AM, you wrote:
MS hello,

MS I'm writing a socket approach to send email directly via an SMTP 
server
MS (since some hosts block sendmail trough php due to abuse). Now, 
I have

MS the code, attached below:
MS I have cut it down slightly so it would still be readable 
though. I'm

MS very sure that none of the stuff I removed actually matters in the
MS problem though (mostly error chechking, logging, debug stuff, etc).

MS Ok, back to the problem. If I reread my log, I see the following 
output:

MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
MS C: HELO ip
MS S:
MS C: MAIL FROM: [EMAIL PROTECTED]
MS S: 250 server OK, server2 [ip].
MS C: RCPT TO: [EMAIL PROTECTED]
MS S:
MS C: RSET

MS Now, obviously, the server sends something back (I checked, 
manually,
MS using telnet). So, I figured that the socket_read(socket, size, 
MS PHP_NORMAL_READ) was causing the problem. So I switched over to 
MS PHP_BINARY_READ to make sure I didn't miss anything (because it 
broke
MS off eg. midways). So... after I changed that, I suddenly started 
getting

MS these errors:
MS Warning: socket_read() unable to read from socket [11]: Resource 
MS temporarily unavailable in /home/me/scripts/mail.php on line 27


MS This goes for each attempt to read (even the first). I'm 
stumped... and

MS really don't know how to proceed now...

MS Does anyone have any clues?
MS very appreciated,

Because of this line the function returns straight away.

MS socket_set_nonblock($this-socket);

You have to catch the 'not ready' error something like this:
(The error code was under windows)

function get(){
  $ret = '';
  while(1){
$sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ);
if(false === $sbuf){
  $error = socket_last_error($this-connection);
  if($error != 10035){
echo msgsock read() failed: reason:  .$error.' '. 
socket_strerror (socket_last_error($this-connection)) . \n;

return;//socket not happy
  }
}else{
  $buf_read = strlen($sbuf);
  if($buf_read === 0) break; // end of text
  $ret .= $sbuf;
}
  }
  return $ret;
}







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 
2005-09-02












--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-02 Thread M. Sokolewicz

hello,

I'm writing a socket approach to send email directly via an SMTP server 
(since some hosts block sendmail trough php due to abuse). Now, I have 
the code, attached below:
I have cut it down slightly so it would still be readable though. I'm 
very sure that none of the stuff I removed actually matters in the 
problem though (mostly error chechking, logging, debug stuff, etc).


Ok, back to the problem. If I reread my log, I see the following output:
S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
C: HELO ip
S:
C: MAIL FROM: [EMAIL PROTECTED]
S: 250 server OK, server2 [ip].
C: RCPT TO: [EMAIL PROTECTED]
S:
C: RSET

Now, obviously, the server sends something back (I checked, manually, 
using telnet). So, I figured that the socket_read(socket, size, 
PHP_NORMAL_READ) was causing the problem. So I switched over to 
PHP_BINARY_READ to make sure I didn't miss anything (because it broke 
off eg. midways). So... after I changed that, I suddenly started getting 
these errors:
Warning: socket_read() unable to read from socket [11]: Resource 
temporarily unavailable in /home/me/scripts/mail.php on line 27


This goes for each attempt to read (even the first). I'm stumped... and 
really don't know how to proceed now...


Does anyone have any clues?
very appreciated,

- Tul

P.S. see attached, code:
?php
class socket_SMTP {
var $socket = null;

function connect($host, $port, $user, $pass) {
$this-socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this-socket  0) {
			exit(socket_create() failed: reason:  . 
socket_strerror($this-socket) . \n);

}

$res = socket_connect($this-socket, gethostbyname($host), 
$port);
if(false === $res) {
echo 'No connection';
return false;
}
socket_set_nonblock($this-socket);
$this-get();
$this-send('HELO '.'my-servers-ip-addy-goes-here');
$this-get();// ignore res
}

function send($cmd) {
socket_write($this-connection, $cmd.\r\n, 
strlen($cmd.\r\n));
}

function get() {
$ret = socket_read($this-connection, 1024, PHP_BINARY_READ);
return $ret;
}

function sendMessage($from, $to, $message, $headers) {
$headers = $this-safeData($headers);
$message = $this-safeData($message);

$this-send('MAIL FROM: '.$from.'');
$this-send('RCPT TO: '.$to.'');
$this-send('DATA');
$this-send($headers);
$this-send(''); // CRLF to distinguish between headers and 
message
$this-send($message);
$this-send('.');

// sent message
return true;
}

function disconnect() {
$this-send('QUIT');
socket_close($this-socket);
}
}
$mail = new socket_SMTP();
$mail-connect('mail.server.com', '25', 'username', 'password');
$mail-sendMessage('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', 'Test message', 
'Subject: whatever-test-mail'.\r\n);

$mail-disconnect();
?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php