Call fputs from inside function, fsockopen outside?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EndTwist
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2004 6:40 pm

Call fputs from inside function, fsockopen outside?

Post by EndTwist »

Hello again,

How can I call fputs from inside a function, when I have opened the connection outside it?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

Code: Select all

<?php
function myfunction($fpcon){
    fputs($fpcon,"GET / HTTP/1.0\n\n");
}

$fp = fsockopen("www.php.net", 80, $errno, $errstr, 30);
myfunction($fp);
?>
EndTwist
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2004 6:40 pm

Post by EndTwist »

Thats what I thought, but I get a "30 second timeout" when I try that.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

it works using it outside the function
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

EndTwist wrote: Thats what I thought, but I get a "30 second timeout" when I try that.
Did you try using a '&'. In other words, passing the socket resource in by reference.

Code: Select all

/* Notice that the resource is passed in by reference */
function myfunction(&$fpcon)
    { fputs($fpcon,"GET / HTTP/1.0\n\n"); }

$fp = fsockopen("www.php.net", 80, $errno, $errstr, 30);
myfunction($fp);
See if that works.

Cheers,
BDKR
EndTwist
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2004 6:40 pm

Post by EndTwist »

unfortunately, it didn't help

Code: Select all

sendProc(1, chr(0) . chr(0) . chr(0) . chr(1) . chr(0) . chr($snFiller) . chr(strlen($screenName)) . $screenName, $socks);
	sendProc(2, "toc_signon login.oscar.aol.com " . randomdigit(1) . "234 " . $screenName . " " . $encPassword . " english " . chr(34) . "AOLInstantMessenger" . chr(34) . chr(0), $socks);

function sendProc($frameType, $strWTS, &$socks) {
  if (strlen($strWTS) > 2048) { exit; }

  $lngSeqHi = Hi(1);
  $lngSeqLo = Lo(1);
  $lngLen = strlen($strWTS);
  $lngLenHi = Hi($lngLen);
  $lngLenLo = Lo($lngLen);
  $strOut = "*" . chr($frameType) . chr($lngSeqLo) . chr($lngSeqHi) . chr($lngSeqLo) . chr($lngSeqHi) . $strWTS;
  fputs($socks, $strOut);
}
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

just a question... did you try to use it without the function?

maybe the function stuff is working..
Post Reply