fsockopen

PHP fsockopen doesnt return anything

不想你离开。 提交于 2019-12-13 03:01:16
问题 I am modifying a PHP db wrapper for the redis database. Here's how my function looks: public function connect() { $sock = @fsockopen('localhost', '6379', $errno, $errstr, 2); if ($sock === FALSE) { return FALSE; } else { stream_set_timeout($sock, 2); return $sock; } } What I want to do is to call this function from another part in my wrapper: if ($this->connect() !== FALSE) { // Do stuff } How can I get my connect function to send a FALSE when the fsockopen isn't working? Thanks! 回答1: From a

using php Download File From a given URL by passing username and password for http authentication

北战南征 提交于 2019-12-12 18:42:42
问题 I need to download a text file using php code. The file is having http authentication. What procedure I should use for this. Should I use fsocketopen or curl or Is there any other way to do this? I am using fsocketopen but it does not seem to work. $fp=fsockopen("www.example.com",80,$errno,$errorstr); $out = "GET abcdata/feed.txt HTTP/1.1\r\n"; $out .= "User: xyz \r\n"; $out .= "Password: xyz \r\n\r\n"; fwrite($fp, $out); while(!feof($fp)) { echo fgets($fp,1024); } fclose($fp); Here fgets is

PHP fsockopen Is Slow

雨燕双飞 提交于 2019-12-12 02:16:47
问题 I'm playing around with the IMAP protocol in PHP using fsockopen to send and receive commands. My preliminary experiments work but are insanely slow. It takes about 2 minutes for the simple function below to run. I've tried several different IMAP servers and have gotten the same result. Can anyone tell me why this code is so slow? <?php function connectToServer($host, $port, $timeout) { // Connect to the server $conn = fsockopen($host, $port, $errno, $errstr, $timeout); // Write IMAP Command

Creating a TCP socket connection and sending through a XML request in order to get an XML response?

不问归期 提交于 2019-12-11 11:36:16
问题 The port is 5792 and the ip is 123.123.123.123. I am able to send data to the ip, like so: $host = "tcp://123.123.123.123"; $port = 5792; $errstr = ''; $errno = ''; $fp = fsockopen($host, $port ,$errno, $errstr, 30); if (!$fp) { print 'COULD NOT CONNECT! <br />'; echo "$errstr ($errno)<br />\n"; die(); } else { print 'SUCCESS!<br />' } The sending seems to also work: $message = 'hello'; fputs ($fp, $message ); The problem comes in when receiving data: print fread($fp, 128); This prints: hello

Opening connection to HTTP server with PHP

∥☆過路亽.° 提交于 2019-12-11 07:23:26
问题 I'm trying to open a connection to a webserver I have hosted on an Amazon EC2 instance. I can access the port with a GET request from my browser which gives me the following: Started HTTP server... - <IP redacted> [19/Jul/2013 13:49:24] code 501, message Unsupported method ('GET') - <IP redacted> [19/Jul/2013 13:49:24] "GET / HTTP/1.1" 501 - This is as expected as I haven't implemented GET on the webserver - but I get no response at all using the following snippet to POST to the same port. <

php实现异步轮询

一笑奈何 提交于 2019-12-10 22:32:22
文章目录 一、前言 二、工欲善其事 1、curl是伪异步请求 2、鸟哥推荐的方法中有curl 三、异步轮询(fsockopen) 1、模拟异步轮询的demo 2、响应页面代码 3、测试结果 4、fsockopen(): unable to connect to 错误 四、问题以及反思 1、无法调试返回 2、占用进程 3、最佳方式 4、python,酸,真酸 一、前言 如题所示,对于 phper 来说,异步轮询总是会觉得很麻烦,在不考虑 workman 和 swoole 的情况下, php 总是被人诟病的就是 多线程 和 异步IO 问题了,刚好博主最近有这个需求,下面咱们来一起研究下怎么实现原生的异步轮询。 二、工欲善其事 既然是要做异步,博主的脑海里第一时间浮现的是 curl 的方式,我们平时对于一些外部请求,用的最多的就是 curl 方式,还可以避开 https 的证书验证,那么 curl 的方式符合需求吗? 1、curl是伪异步请求 在不断的百度中,发现大家虽然有用 curl 进行异步请求的,但是不管是 curl 还是 curl_multi 都需要把整个请求池所有请求处理完毕,把所有响应报文拿到,才会继续往下走的。虽然看起来像异步,但是实际上是同步阻塞的。 参考 : 关于 php 通过 curl 的伪异步方式抓取数据,下面这种 curl 方式和普通的 curl

Enable SSL in PHP fsockopen()

泄露秘密 提交于 2019-12-10 20:42:40
问题 I am using PHP fsockopen() to finalize a payment between my server and PayPal. However, when I try to use an SSL connection, I get this error: Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) I am sure that my call to the fsockopen() method is correct, as it worked correctly before I upgraded PHP on my development server. It is important that this connection is

file_get_contents with https requests via proxy

扶醉桌前 提交于 2019-12-10 10:08:22
问题 How to do HTTPS requests via proxy server The proxy server is tinyproxy on debian code $context = stream_context_create([ 'http' => [ 'proxy' => 'tcp://xx.xx.xx.xx:8888', 'request_fulluri' => true ] ]); echo file_get_contents('https://www.google.com', false, $context); error Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in C:\wamp\www\google\test.php on line 10 Warning: file_get

万网虚拟机不能使用smtp的问题解决方法

让人想犯罪 __ 提交于 2019-12-10 00:03:16
昨晚为了自己的网站开发了个简单的发送邮件的功能,在本地测试是成功的,放在万网的虚拟机上却不成功了,一直提示ERROR: Failed to connect to server: (0)。 后面我查了下,发现是服务器关闭了 fsockopen 函数。我就去万网的主机管理里看了看,在万网的主机管理里的网站高级管理,里面有个php函数设置。 这时就可以看到 fsockopen 是默认关闭的,将它开启即可。 来源: oschina 链接: https://my.oschina.net/u/1860083/blog/315356

PHP函数:fsockopen

醉酒当歌 提交于 2019-12-09 23:45:37
fsockopen:打开网络的 Socket 链接    语法: resuce fsockopen(string hostname, int port, int [errno], string [errstr], int [timeout]); 返回值: 资源; 函数种类: 网络系统; 内容说明: 目前这个函数提供两个 Socket 资料流界面,分别为 Internet 用的 AF_INET 及 Unix 用的 AF_UNIX。 在 Internet 中,参数 hostname 及 port 分别代表网址及端口号。 在 UNIX 中,参数hostname 表示到 socket 的路径,port 配置为 0。timeout可省略表示多久没有连上就中断。该函数返回文件指针,供文件函数使用,包括 fgets()、fgetss()、fputs()、fclose()、feof()。参数 errno 及 errstr 可省略,做错误处理使用。该函数使用阻塞模式 (blocking mode) 处理,可用 set_socket_blocking() 转换成无阻塞模式。 实例:   <?php    $fp = fsockopen("php.wilson.gs", 80, &$errno, &$errstr, 10);    if(!$fp) {    echo "$errstr ($errno)