recherche
Maisondéveloppement back-endtutoriel php fsockopen顺利,fwrite失败的原因有哪些

fsockopen成功,fwrite失败的原因有哪些?

经过本地和一台WINDOWS服务器测试都很稳定。

但在LINUX服务器上,fsockopen每次也是成功的,但fwrite却多数都失败,很久才成功一次。。

谁遇到过这样的情况吗。。
另外//注释标记那一部分,谁能解释下。。

代码如下:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$matches = parse_url($url);
    !isset($matches['host']) && $matches['host'] = '';
    !isset($matches['path']) && $matches['path'] = '';
    !isset($matches['query']) && $matches['query'] = '';
    !isset($matches['port']) && $matches['port'] = '';
    $host = $matches['host'];
    $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
    $port = !empty($matches['port']) ? $matches['port'] : 80;
    if($post) {
        $out = "POST $path HTTP/1.0\r\n";
        $out .= "Accept: */*\r\n";
        $out .= "Accept-Language: zh-cn\r\n";
        $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
        $out .= "Host: $host\r\n";
        $out .= 'Content-Length: '.strlen($post)."\r\n";
        $out .= "Connection: Close\r\n";
        $out .= "Cache-Control: no-cache\r\n";
        $out .= "Cookie: $cookie\r\n\r\n";
        $out .= $post;
    } else {
        $out = "GET $path HTTP/1.0\r\n";
        $out .= "Accept: */*\r\n";
        $out .= "Accept-Language: zh-cn\r\n";
        $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
        $out .= "Host: $host\r\n";
        $out .= "Connection: Close\r\n";
        $out .= "Cookie: $cookie\r\n\r\n";
    }
    
    $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
    
    if(!$fp) {
        return '';//note $errstr : $errno \r\n
    } else {
        stream_set_blocking($fp, $block);
        stream_set_timeout($fp, $timeout);var_dump($fp);
        @fwrite($fp, $out);
//注释标记
        /*$status = stream_get_meta_data($fp);
        if(!$status['timed_out']) {
            while (!feof($fp)) {
                if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
                    break;
                }
            }

            $stop = false;
            while(!feof($fp) && !$stop) {
                $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
                $return .= $data;
                if($limit) {
                    $limit -= strlen($data);
                    $stop = $limit 





------解决方案--------------------
检查文件的读写性。
------解决方案--------------------
PHP code

/* 对于楼主的应用, 这里得到的是TCP套接字的一些信息 */
        $status = stream_get_meta_data($fp);
/* 这里是检查TCP连接是否超时 */
        if(!$status['timed_out']) {
/* 如果没有超时, 那么就读取数据, 直到碰到文件结束符 */
            while (!feof($fp)) {
/* 由于这里是读取HTTP头信息, 空行标识头信息结束, 因此需要break */
                if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
                    break;
                }
            }
/* 这里是读取HTTP的body, 个人认为这里的处理有一些粗糙, 至少先看看HTTP响应头中有没有Content-Length根据它进行处理, 如果没有再如下读取 */
            $stop = false;
            while(!feof($fp) && !$stop) {
/* 读取最多8192字节($limit递减) */
                $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
/* 将读取到的内容连接到返回字符串中 */
                $return .= $data;
                if($limit) {
                    $limit -= strlen($data);
                    $stop = $limit <font color="#e78608">------解决方案-------------------- <div class="clear">
                 
              
              
        
            </div></font>
Déclaration
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
主板上的数字音频输出接口-SPDIF OUT主板上的数字音频输出接口-SPDIF OUTJan 14, 2024 pm 04:42 PM

主板上SPDIFOUT连接线序最近我遇到了一个问题,就是关于电线的接线顺序。我上网查了一下,有些资料说1、2、4对应的是out、+5V、接地;而另一些资料则说1、2、4对应的是out、接地、+5V。最好的办法是查看你的主板说明书,如果找不到说明书,你可以使用万用表进行测量。首先找到接地,然后就可以确定其他的接线顺序了。主板vdg怎么接线连接主板的VDG接线时,您需要将VGA连接线的一端插入显示器的VGA接口,另一端插入电脑的显卡VGA接口。请注意,不要将其插入主板的VGA接口。完成连接后,您可以

Laravel中take和limit的使用方法详解Laravel中take和limit的使用方法详解Mar 10, 2024 pm 05:51 PM

《Laravel中take和limit的使用方法详解》在Laravel中,take和limit是两个常用的方法,用于在数据库查询中限制返回的记录数。虽然它们的作用类似,但在具体的使用场景中有一些细微的区别。本文将详细解析这两个方法的用法,并提供具体的代码示例。一、take方法在Laravel中,take方法用于限制返回的记录数,通常结合orderBy方法一起

out和in接口是什么意思out和in接口是什么意思Sep 28, 2021 pm 04:39 PM

out接口指的是输出接口,in接口指的是输入接口。out接口一般代表着音源线路输出接口,用来接负载,例音箱、耳机等;而in接口一般代表着音源线路输入接口,用来接CD机、手机、MP3、电脑等。

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

AMP是什么币?AMP是什么币?Feb 24, 2024 pm 09:16 PM

什么是AMP币?AMP代币是由Synereo团队于2015年创立,作为Synereo平台的主要交易货币。AMP代币旨在通过多种功能和用途,为用户提供更好的数字经济体验。AMP代币的用途AMP代币在Synereo平台中拥有多重角色和功能。首先,作为平台的加密货币奖励系统的一部分,用户能够通过分享和推广内容来获得AMP奖励,这一机制鼓励用户更积极地参与平台的活动。AMP代币还可用于在Synereo平台上推广和传播内容。用户可以通过使用AMP代币提升他们的内容在平台上的曝光率,以吸引更多观众来查看和分

Laravel中take和limit的功能及用法对比Laravel中take和limit的功能及用法对比Mar 09, 2024 pm 09:09 PM

Laravel中take和limit是两种常用的方法,用于限制查询结果集的数量。虽然它们在功能上有一定的相似之处,但在使用方式和一些细节上有所不同。本文将对这两种方法的功能及用法进行详细对比,同时提供具体的代码示例,帮助读者更好地理解它们之间的区别和如何正确地应用。1.take方法take方法是LaravelEloquent查询构建器中

win10系统闪退显示out of memory怎么办?win10系统闪退显示out of memory怎么办?Feb 09, 2024 pm 03:00 PM

win10系统闪退显示outofmemory,近期很多的用户在使用电脑的时候,出现了这个提示,导致需要经常的重启进行修复,那么这种情况我们应该如何处理,针对这个问题,本期的win10教程就来和广大用户们分享完整操作步骤,希望能够帮助更多的小伙伴解决问题。win10系统闪退显示outofmemory怎么办1、右击桌面上的此电脑,选择选项列表中的“属性”。2、进入到新的窗口界面后,点击左上角的“高级系统设置”选项。3、在打开的窗口中,切换到上方中的“

如何使用Java中的Stream的limit和skip函数进行流操作如何使用Java中的Stream的limit和skip函数进行流操作Jun 26, 2023 pm 03:55 PM

Java8中引入了StreamAPI,它能够极大地简化对集合的操作。Stream类提供了许多用于操作流的函数式方法,包括过滤、映射、合并等等。其中,limit和skip是用于流操作中限制元素数量的两个函数。一、limit函数limit函数用于限制流中元素的数量,它接受一个long类型的参数n,表示限制的数量。调用limit函数后,返回一个新的流,它仅包含

See all articles

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
2 Il y a quelques semainesBy尊渡假赌尊渡假赌尊渡假赌
Repo: Comment relancer ses coéquipiers
4 Il y a quelques semainesBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
4 Il y a quelques semainesBy尊渡假赌尊渡假赌尊渡假赌

Outils chauds

PhpStorm version Mac

PhpStorm version Mac

Le dernier (2018.2.1) outil de développement intégré PHP professionnel

Dreamweaver Mac

Dreamweaver Mac

Outils de développement Web visuel

Listes Sec

Listes Sec

SecLists est le compagnon ultime du testeur de sécurité. Il s'agit d'une collection de différents types de listes fréquemment utilisées lors des évaluations de sécurité, le tout en un seul endroit. SecLists contribue à rendre les tests de sécurité plus efficaces et productifs en fournissant facilement toutes les listes dont un testeur de sécurité pourrait avoir besoin. Les types de listes incluent les noms d'utilisateur, les mots de passe, les URL, les charges utiles floues, les modèles de données sensibles, les shells Web, etc. Le testeur peut simplement extraire ce référentiel sur une nouvelle machine de test et il aura accès à tous les types de listes dont il a besoin.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) est une application Web PHP/MySQL très vulnérable. Ses principaux objectifs sont d'aider les professionnels de la sécurité à tester leurs compétences et leurs outils dans un environnement juridique, d'aider les développeurs Web à mieux comprendre le processus de sécurisation des applications Web et d'aider les enseignants/étudiants à enseigner/apprendre dans un environnement de classe. Application Web sécurité. L'objectif de DVWA est de mettre en pratique certaines des vulnérabilités Web les plus courantes via une interface simple et directe, avec différents degrés de difficulté. Veuillez noter que ce logiciel

MinGW - GNU minimaliste pour Windows

MinGW - GNU minimaliste pour Windows

Ce projet est en cours de migration vers osdn.net/projects/mingw, vous pouvez continuer à nous suivre là-bas. MinGW : un port Windows natif de GNU Compiler Collection (GCC), des bibliothèques d'importation et des fichiers d'en-tête librement distribuables pour la création d'applications Windows natives ; inclut des extensions du runtime MSVC pour prendre en charge la fonctionnalité C99. Tous les logiciels MinGW peuvent fonctionner sur les plates-formes Windows 64 bits.