1.python写法
import socket
def get_remote_machine_info():
remote_host = 'www.python.org'
try:
print "IP address of %s: %s" %(remote_host, socket.gethostbyname(remote_host))
except socket.error, err_msg:
print "%s: %s" %(remote_host, err_msg)
if __name__ == '__main__':
get_remote_machine_info()2.php写法
<?php
function get_remote_machine_info(){
$remote_host = 'www.python.org';
try{
printf("IP address of %s: %s\n", $remote_host, gethostbyname($remote_host));
}catch(Exception $e){
printf("%s: %s\n", $remote_host, $e->getMessage());
}
}
get_remote_machine_info();代码比较简单 但执行起来还是php比较慢~
转载请标注原文地址:http://blog.youkuaiyun.com/ddjohn/article/details/49930455

本文对比了Python和PHP两种编程语言在获取远程主机IP地址时的方法和性能表现,通过简单的代码示例展示如何实现,并指出PHP在执行速度上的劣势。
476

被折叠的 条评论
为什么被折叠?



