fsockopen

fsockopen returning server error(0)

一曲冷凌霜 提交于 2020-06-14 07:54:13
问题 I'm checking fsockopen in Ubuntu server 13.04 with this code: <?php $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> and the server returning php_network_getaddresses: getaddrinfo failed: System error (0) Any help with this? 回答1: There is no

PHP快速检测死链接

邮差的信 提交于 2020-03-26 18:11:24
3 月,跳不动了?>>> 检测死链接的原理是发起一个http请求,然后分析返回的状态码,如果是200,就说明链接可用,如果是404或者50x等等,就说明是死链接。 很容易想到用curl去完成这个任务,我今天分享一个不依赖curl并且更加高效的方法:使用socket。 步骤: 1、使用socket建立一个TCP连接: $socket = fsockopen('ssl://www.baidu.com', 443, $errorno, $erromsg, 5); if (empty($socket)) throw new \RuntimeException('连接服务器失败'); //因为baidu.com是https协议,所以需要加上ssl://前缀,端口使用443 //若你需要检测的网站是http协议,那么就去掉前缀,端口使用80 $socket = fsockopen('www.test.com', 80, $errorno, $erromsg, 5); 2、发起一个http请求: // 检测链接为:https://www.baidu.com/img/bd_logo1.png?where=super $request = "GET /img/bd_logo1.png?where=super HTTP/1.1\r\n\r\n"; fwrite($socket, $request);

php中使用Curl、socket、file_get_contents三种方法POST提交数据

半城伤御伤魂 提交于 2020-02-12 04:47:20
抓取远程内容,之前一直都在用file_get_content函数,其实早就知道有curl这么一个好东西的存在,但是看了一眼后感觉使用颇有些复杂,没有file_get_content那么简单,再就是需求也不大,所以没有学习使用curl。 直到最近,要做一个网页小偷程序的时候才发现file_get_content已经完全不能满足需求了。我觉得,在读取远程内容的时候,file_get_content除了使用比curl便捷以外,其他都没有curl好。 php中curl和file_get_content的一些比较 主要区别: 学习才发现,curl支持很多协议,有FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE以及LDAP,也就是说,它能做到很多file_get_content做不到的事情。curl在php可以实现远程获取和采集内容;实现PHP网页版的FTP上传下载;实现模拟登陆;实现接口对接(API),数据传输;实现模拟Cookie;下载文件断点续传等等,功能十分强大。 了解curl一些基本的使用后,才发现其实并不难,只不过记住里面一些设置参数,难弄一点,但是我们记住几个常用的就可以了。 开启curl: 因为PHP默认是不支持curl功能的,因此如果要用curl的话,首先需要在php.ini中开启该功能,即去掉 ;extension=

PHP模拟发送POST请求之三、用Telnet和fsockopen()模拟发送POST信息

本秂侑毒 提交于 2020-02-12 04:39:35
了解完了HTTP头信息和URL信息的具体内容,我们开始尝试自己动手写一段头信息发送到服务器。Windows内置命令Telnet可以帮助我们发送简单的HTTP请求。 并且TELNET是一个特别灵活的工具,我们还可以用它进行FTP/SMTP/POP3/TCP等方式的简单请求。 通过开始菜单--运行--CMD命令进入DOS状态, 我们输入“Telnet 主机地址 端口(Telnet 192.168.1.99 80)” 来进入telnet命令状态(完全黑窗口,此时输出字符会出问题),我们按”ctrl”+”]”,切回普通CMD窗口,再按”ENTER”回车键进入编辑命令状态。 如果系统提示找不到TELNET命令,只需按如下方式可解锁TELNET命令。 进入TELNET 命令输入模式后我们就可以直接编辑头文件来进行发送了 只需要注意:当编辑完请求头文件后要按两次回车键来发送。 这是一次标准的HTTP请求与响应,是不是跟上节的HTTP文件关联了。 当然我们不能只用这么不方便的工具,下面要介绍的是PHP里的 fsockopen() 方法。 先来看fsockopen()方法的原型: resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout =

Can I open socket in PHP from a specific IP (if the machine has two IPs)?

故事扮演 提交于 2020-02-02 06:54:12
问题 I'm using PHPMailer and it uses fsockopen to access the SMTP server. But the machine has two IPs with different reverse DNS records. So in email headers I got the following: Received: from one-server.tld (HELO another-server.tld) ... I need to hide one-server.tld in favor of another-server.tld . But I need both IPs with their current RDNS settings. 回答1: I think its not possible using fsockopen . But its possible in curl , fopen and stream functions. What you need is stream_socket_client()

How to use fsockopen (or compatible) with SOCKS proxies in PHP?

和自甴很熟 提交于 2020-01-24 09:55:12
问题 I've coded a non-evil, non-spammy IRC bot in PHP, using fsockopen and related functions. It works. However, the problem is that I need to support proxies (preferably SOCKS5, but HTTP is also OK if that is somehow easier, which I doubt). This is not supported by fsockopen . I've gone through all search results for "PHP fsockopen proxy" and related queries. I know of all the things that don't work, so please don't link to one of them. The PHP manual page for fsockopen mentions the function

live audio stream socket get stuck in browser

我的未来我决定 提交于 2020-01-22 19:49:30
问题 I'm trying to setup a page where several (private) streams can be listened from. Unfortunately I'm not able to get it running. I tried Using php to opening live audio stream on android already, but for some reason the browser get stuck when loading the script. See below script with an example of a working host (see http://icecast.omroep.nl/radio4-bb-mp3) Could someone please enlighten me. Tnx in advance! $host = "icecast.omroep.nl"; $port = 80; $sub = "/radio4-bb-mp3"; $sock = fsockopen($host

php fsockopen unable to connect, connection timeout error

╄→尐↘猪︶ㄣ 提交于 2020-01-14 05:49:27
问题 I am running a local apache server on an ubuntu machine, and i am trying to use the phpmailer class to send mail. It tries to connect by fsockopen to the mail server, but it throws a timeout error. I tried setting the timeout to 15sec with no luck. It does work on other machines. How can i find out if my ISP has blocked requests ? The mail server responds to ping. 回答1: ping and SMTP command don't go via the same port ; it is possible that one port is opened, and not the other one. If there is

How do I pass session to new socket via fsockopen?

*爱你&永不变心* 提交于 2020-01-11 07:49:08
问题 I need to pass the session to an asynchronous call via fsockopen in php. Can you help me pass the session to the new socket? SOLUTION: The following code works. start.php <?php session_start(); $_SESSION['var1'] = 'value1'; async_call('/async.php'); echo '<pre>'; print_r($_SESSION); echo $_COOKIE['PHPSESSID'] . "\r\n"; echo '<a href="verify.php">verify.php</a>'; function async_call($filepath) { $host = 'sandbox'; // set to your domain $sock = fsockopen($host, 80); fwrite($sock, "GET $filepath

PayPal IPN and fsockopen

烈酒焚心 提交于 2020-01-06 19:56:55
问题 Well I can't use cURL, the version installed on my web host that can't be changed doesn't support TLS. I'm trying to use fsockopen now to see if i'll be able to use IPN. It just hangs and browser throws connection timeout. PHP 7, open_ssl is enabled <?php header('HTTP/1.1 200 OK'); $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST[