1)你ssh登录到服务器上。
2)输出which php,看看输出是什么,/usr/local/bin/php只是一种可能的情况,还有可能是/usr/bin/php等
3)输入crontab -e,回车。把*/1 * * * * /usr/local/bin/php /root/wwwroot/test/a.php输入进去,保存,退出。记住,这里的“/usr/local/bin/php”只是一种可能性,不一定是这个,要看which php的输出。
4)上面的*/1表示每分钟后台执行一次,等结果吧。通过这个帖子了解了很多,目前还有个疑问,就是帖子中提到的那个被定时调用的a.php,完全如传统web开发一样来写PHP代码是否就可以了。随便我用什么函数、数据库操作、SESSION都没问题吧?
自己的独立主机,想做什么设置都可以
2)输出which php,看看输出是什么,/usr/local/bin/php只是一种可能的情况,还有可能是/usr/bin/php等
3)输入crontab -e,回车。把*/1 * * * * /usr/local/bin/php /root/wwwroot/test/a.php输入进去,保存,退出。记住,这里的“/usr/local/bin/php”只是一种可能性,不一定是这个,要看which php的输出。
4)上面的*/1表示每分钟后台执行一次,等结果吧。通过这个帖子了解了很多,目前还有个疑问,就是帖子中提到的那个被定时调用的a.php,完全如传统web开发一样来写PHP代码是否就可以了。随便我用什么函数、数据库操作、SESSION都没问题吧?
自己的独立主机,想做什么设置都可以
$port = "1234";//设置超时时间
set_time_limit(0); // 创建一个Socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); //绑定Socket到端口
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// 开始监听链接
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // accept incoming connections
// 另一个Socket来处理通信
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");// 获得客户端的输入
$input = socket_read($spawn, 1024) or die("Could not read input\n"); // 清空输入字符串
$input = trim($input); //处理客户端输入并返回结果
$output = strrev($input) . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
// 关闭sockets
socket_close($spawn);
socket_close($socket);
$port = "1234";//设置超时时间
set_time_limit(0); // 创建一个Socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); //绑定Socket到端口
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// 开始监听链接
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // accept incoming connections
// 另一个Socket来处理通信
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");// 获得客户端的输入
$input = socket_read($spawn, 1024) or die("Could not read input\n"); // 清空输入字符串
$input = trim($input); //处理客户端输入并返回结果
$output = strrev($input) . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
// 关闭sockets
socket_close($spawn);
socket_close($socket);