tomfmason Posted August 20, 2006 Share Posted August 20, 2006 Ok I am attempting to create a script that will accept in comming email. I thought that sockets would be the way to go. This is what I have so far(this is an extreme beta verson)[code]<?php$port = "25";$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);if ($socket == false) { die("Error in createing the socket, the error code is " . socket_last_error() . " and the error message is " . socket_strerror(socket_last_error()));}if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { die("Unable to set socket option. The error is " . socket_last_error() . " and the error message is " . socket_strerror(socket_last_error()));} $bind = socket_bind($socket, NULL, $port);if ($bind == false) { socket_close($socket); die("socket_bind failed. The error code is " . socket_last_error() . " and the error message is " . socket_strerror(socket_last_error()));}$listen = socket_listen($socket, SOMAXCONN);if ($listen == false) { socket_close($socket); die("socket_listen failed. The error code is " . socket_last_error() ." and the error message is " . socket_strerror(socket_last_error()));}socket_accept($socket);while (socket_recv($socket, $mail, 77, 2)) { echo "$mail";}usleep(10000);echo "This test worked and we are listening on port $port";socket_close($socket); ?>[/code]All this does is listen to port 25. My first question is how can I have this script continuously listening to the port?Should I use [code=php:0]socket_read()[/code] instead of accept?Any suggestions would be great.Thanks,Tom Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.