Foros del Web » Programando para Internet » PHP »

Error fwrite

Estas en el tema de Error fwrite en el foro de PHP en Foros del Web. Hola van a disculpar el titulo, pero me aparece el siguiente error: Código PHP: Warning :  fwrite ():  supplied argument is not a valid stream resource in  / home / wwwguia / public_html ...
  #1 (permalink)  
Antiguo 08/06/2007, 10:02
 
Fecha de Ingreso: abril-2005
Ubicación: en Santa Cruz - España
Mensajes: 429
Antigüedad: 19 años
Puntos: 1
Error fwrite

Hola van a disculpar el titulo, pero me aparece el siguiente error:

Código PHP:
Warningfwrite(): supplied argument is not a valid stream resource in /home/wwwguia/public_html/msn_contact_grab.class.php on line 380

Warning
fwrite(): supplied argument is not a valid stream resource in /home/wwwguia/public_html/msn_contact_grab.class.php on line 380

Warning
stream_get_meta_data(): supplied argument is not a valid stream resource in /home/wwwguia/public_html/msn_contact_grab.class.php on line 181

Warning
feof(): supplied argument is not a valid stream resource in /home/wwwguia/public_html/msn_contact_grab.class.php on line 183 
y el codigo es el siguiente
Código PHP:
<?php

class msn
{
    
// messenger.hotmail.com is an exchange server
    // using it will redirect to a server with an open slot
    // using a known server ip will help connect faster

    // commenting out $ssh_login will mean the url to the
    // secure login server will be taken from a secure
    // session.  this will slow down connecting a bit.
    // Note: comment out $ssh_login if you experience auth failures

    
var $server    =    'messenger.hotmail.com';
    var 
$port    =    1863;

    var 
$nexus    =    'https://nexus.passport.com/rdr/pprdr.asp';
    var 
$ssh_login    =    'login.live.com/login2.srf';

    var 
$debug    =    0;


    
// curl is used for the secure login, if you don't have
    // the php_curl library installed, you can use a curl binary
    // instead. $use_curl needs to be set to 1 to enable this.
    // set $curl to the path where curl is installed.
    // curl can be downloaded here: http://curl.haxx.se/download.html

    
var $curl_bin    =    0;
    var 
$curl    =    '/usr/local/bin/curl';    // linux
    //var $curl    =    'c:\curl.exe';        // windows

    //Used to prevent the script from hanging
    
var $count 0;
    
    
//Used to store the email addresses until all have been collected
    
var $email_input = array();
    var 
$email_processing = array();
    var 
$email_output = array();
    var 
$fp;

    
/**
     *
     * desc    :    Connect to MSN Messenger Network
     *
     * in    :    $passport    =    passport i.e: [email protected]
     *        $password    =    password for passport
     *
     * out    :    true on success else return false
     *
     */

    
function connect($passport$password)
    {
        
$this->trID 1;

        if (!
$this->fp = @fsockopen($this->server$this->port$errno$errstr2)) {
            
            die(
"Could not connect to messenger service");
        
        } else {
              
stream_set_timeout($this->fp2);
              
            
$this->_put("VER $this->trID MSNP9 CVR0\r\n");

            while (! 
feof($this->fp))
            {
                
$data $this->_get();

                switch (
$code substr($data03))
                {
                    default:
                        echo 
$this->_get_error($code);

                        return 
false;
                    break;
                    case 
'VER':
                        
$this->_put("CVR $this->trID 0x0409 win 4.10 i386 MSNMSGR 7.0.0816 MSMSGS $passport\r\n");
                    break;
                    case 
'CVR':
                        
$this->_put("USR $this->trID TWN I $passport\r\n");
                    break;
                    case 
'XFR':
                        list(, , , 
$ip)  = explode (' '$data);
                        list(
$ip$port) = explode (':'$ip);

                        if (
$this->fp = @fsockopen($ip$port$errno$errstr2))
                        {
                            
$this->trID 1;

                            
$this->_put("VER $this->trID MSNP9 CVR0\r\n");
                        }
                        else
                        {
                            if (! empty(
$this->debug)) echo 'Unable to connect to msn server (transfer)';

                            return 
false;
                        }
                    break;
                    case 
'USR':
                        if (isset(
$this->authed))
                        {
                            return 
true;
                        }
                        else
                        {
                            
$this->passport $passport;
                            
$this->password urlencode($password);

                            list(,,,, 
$code) = explode(' 'trim($data));

                            if (
$auth $this->_ssl_auth($code))
                            {
                                
$this->_put("USR $this->trID TWN S $auth\r\n");

                                
$this->authed 1;
                            }
                            else
                            {
                                if (! empty(
$this->debug)) echo 'auth failed';

                                return 
false;
                            }
                        }
                    break;
                }
            }
        }
        
    }

    
//Collects the raw data containing the email addresses
    
function rx_data()
    {
        
$this->_put("SYN $this->trID 0\r\n");
        
        
//Supplies the second MSG code which stops
        //the script from hanging as it waits for


        //more content
        
$this->_put("CHG $this->trID NLN\r\n");
        
        
$stream_info stream_get_meta_data($this->fp);
        
//the count check prevents the script hanging as it waits for more content
        
while ((! feof($this->fp)) && (! $stream_info['timed_out']) && ($this->count <= 1))
        {
            
$data $this->_get();
            
$stream_info stream_get_meta_data($this->fp);
            
            if (
$data)
            {
                switch(
$code substr($data03))
                {
                    default:
                        
// uncommenting this line here would probably give a load of "error code not found" messages.
                        //echo $this->_get_error($code);
                    
break;
                    case 
'MSG':
                       
//This prevents the script hanging as it waits for more content
                       
$this->count++;
                    break;
                    case 
'LST':
                       
//These are the email addresses
                       //They need to be collected in email_input
                       
                       
$this->email_input[] = $data;
                       
                    break;
                    case 
'CHL':
                        
$bits explode (' 'trim($data));

                        
$return md5($bits[2].'Q1P7W2E4J9R8U3S5');
                        
$this->_put("QRY $this->trID [email protected] 32\r\n$return");
                    break;
                    
                }
            }
        }
        
    }
    
    
//This function extracts the emails and screen names from the raw data 
    //collected by rx_data
    
function process_emails () {
      
      
//Neaten up the emails
      
      //$regex = "|^LST\s(\S+?)\s(\S+?)\s\d+?\s\d+?$|";
      
foreach($this->email_input as $email_entry) {
        
        
//Seperate out the email from the name and other data
        
$this->email_processing[] = explode(" "$email_entry);
                        
      }
      
      
//Get rid of the unnecessary data and clean up the name
      
foreach($this->email_processing as $email_entry){
        
        
$this->email_output[] = array(=> $email_entry['1'],
                                        
=> urldecode($email_entry[2]));
    }
    
    
//var_dump($this->email_processing);
    //var_dump($this->email_output);
      
      
      
  
}

    
//This is a quick way of calling all the seperate functions
    //needed to grab the contact list
    
function qGrab ($username$password) {
      
      
//Connect to the MSNM service
      
$this->connect($username$password);
      
      
//Get data
      
$this->rx_data();
      
      
//Process emails
      
$this->process_emails();
      
      
//send the email array
      
return $this->email_output;
      
      
    }


    
/*====================================*\
        Various private functions
    \*====================================*/

    
function _ssl_auth($auth_string)
    {
        if (empty(
$this->ssh_login))
        {
            if (
$this->curl_bin)
            {
                
exec("$this->curl -m 60 -LkI $this->nexus"$header);
                
$header implode($headernull);
            }
            else
            {
                
$ch curl_init($this->nexus);

                
curl_setopt($chCURLOPT_HEADER1);
                
curl_setopt($chCURLOPT_NOBODY1);
                
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
                
curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
                
curl_setopt($chCURLOPT_RETURNTRANSFER1);
                
// curl_setopt($ch, CURLOPT_TIMEOUT, 2);

                
$header curl_exec($ch);

                
curl_close($ch);
            }

            
preg_match ('/DALogin=(.*?),/'$header$out);

            if (isset(
$out[1]))
            {
                
$slogin $out[1];
            }
            else
            {
                return 
false;
            }
        }
        else
        {
            
$slogin $this->ssh_login;
        }


        if (
$this->curl_bin)
        {
            
$header1 '"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string.'"';

            
exec("$this->curl -m 60 -LkI -H $header1 https://$slogin"$auth_string);

            
$header null;

            foreach (
$auth_string as $key => $value)
            {
                if (
strstr($value'Unauthorized'))
                {
                    echo 
'Unauthorised';
                    return 
false;
                }
                elseif (
strstr($value'Authentication-Info'))
                {
                    
$header $value;
                }
            }
        }
        else
        {
            
$ch curl_init('https://'.$slogin);
            
curl_setopt($chCURLOPT_HTTPHEADER, array(
                            
'Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string,
                            
'Host: login.passport.com'
                            
));

            
curl_setopt($chCURLOPT_HEADER1);
            
curl_setopt($chCURLOPT_NOBODY1);
            
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
            
curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
            
curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
// curl_setopt($ch, CURLOPT_TIMEOUT, 2);

            
$header curl_exec($ch);

            
curl_close($ch);
        }

        
preg_match ("/from-PP='(.*?)'/"$header$out);

        return (isset(
$out[1])) ? $out[1] : false;
    }


    function 
_get()
    {
        if (
$data = @fgets($this->fp4096))
        {
              
          
            if (
$this->debug) echo "<div class=\"r\">&lt;&lt;&lt; $data</div>\n";

            return 
$data;
        }
        else
        {
            return 
false;
        }
    }


    function 
_put($data)
    {
        
fwrite($this->fp$data);

        
$this->trID++;

        if (
$this->debug) echo "<div class=\"g\">&gt;&gt;&gt; $data</div>";
    }

}
?>
cual puede ser el problema???

saludos...
  #2 (permalink)  
Antiguo 08/06/2007, 12:10
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Error fwrite

Desde el primer error te indica el problema, a la hora de estar usando fwrite le estas pasando un recurso que no se pudo iniciar, viendo tu codigo, el problema lo mas seguro es que sea que no se puede conectar al servidor.

Saludos.
  #3 (permalink)  
Antiguo 08/06/2007, 12:31
 
Fecha de Ingreso: abril-2005
Ubicación: en Santa Cruz - España
Mensajes: 429
Antigüedad: 19 años
Puntos: 1
Re: Error fwrite

este mismo script lo hago funcionar en mi servidor que tengo instalado en mi pc y funciona perfectamente, pero cuando lo subo a mi hosting sale este errror.

saludos...
  #4 (permalink)  
Antiguo 11/06/2007, 11:11
 
Fecha de Ingreso: abril-2005
Ubicación: en Santa Cruz - España
Mensajes: 429
Antigüedad: 19 años
Puntos: 1
Re: Error fwrite

que tipo de problema puede tener mi servidor hosting para que me genere este error??
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:53.