★ wanayoo — archive 1999 http://www.php.net/manual/function.pfsockopen.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Network
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Network
* checkdnsrr
* closelog
* debugger_off
* debugger_on
* fsockopen
* gethostbyaddr
* gethostbyname
* gethostbynamel
* getmxrr
* getprotobyname
* getprotobynumber
* getservbyname
* getservbyport
* openlog
* pfsockopen
* socket_set_blocking
* syslog
* ip2long
* long2ip
Manual: pfsockopen
View the source code for this pageSearch the site



Previous page
 openlog
 Updated
Sat, 12 Aug 2000
socket_set_blocking 
Next page


pfsockopen

(PHP3 >= 3.0.7, PHP4 )

pfsockopen --  Open persistent Internet or Unix domain socket connection

Description

int pfsockopen (string hostname, int port [, int errno [, string errstr [, int timeout]]])

This function behaves exactly as fsockopen() with the difference that the connection is not closed after the script finishes. It is the persistent version of fsockopen().


User Contributed Notes: pfsockopen


guage@usa.net
09-Feb-2000 06:52
This functions does keep it's connection but seems to create another connection when called again when a webpage is reloaded even though pfsockopen is called with the exact same arguments.


jonathan@sharpmedia.net
26-Apr-2000 07:53
RE: Above note, yes it will open a new connection and return a different id if you don't have your script check to see if there's already a connection. Use the following code:
<pre>
/* Check to see if a connection is already open */
if(!isset($mysocket)){
$mysocket = pfsockopen("myhost.com", "80", '', '', "60"); }
else{
fputs($mysocket,"GET / HTTP/1.0\n\n");
while(!feof($mysocket)) {
echo fgets($mysocket,128);
}
fclose($mysocket);

}

/* Make sure to include $mysocket when calling this script */
echo "<input type=\"hidden\" name=\"mysocket\" value=\"$mysocket\">";

/* or use */
echo "<a href=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2F%5C%26quot%3B%24PHP_SELF%3Fmysocket%3D%24mysocket%5C%26quot%3B%26gt%3BDo&y=1999 Foo</a>";



jonathan@sharpmedia.net
09-May-2000 08:31
RE: the above code, in theory it works, but I tried it on a HTTP server and when I would click the link it would give a "File identifier not found" so I thought either the server was closing the connection or it was wrong, I then tried it with a mail server with the timeout set to 180 and same thing, I'm not sure that the PHP implementation I'm running will retain the fileid (returned by pfsockopen)...anyway...good luck and if anyone finds a work around please let me know!


dnserror@skinnykid.net
28-Jul-2000 12:36
actually the above code will work, given that there is no timeout.


if you set the timeout to 180, then you would have access to the port for that long, but it gives the socket not found when you click a link because after the socket timeout, persistant or not, the socket is closed.



 About Notes


Previous page
 openlog
 Updated
Sat, 12 Aug 2000
socket_set_blocking 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.