note 31486 added to function.include

From: Date: Wed, 23 Apr 2003 19:59:49 +0000
Subject: note 31486 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-46990@lists.php.net to get a copy of this message
If you're needing to include pieces of a page from another server (I do this to have a public poll mirrored on two separate web sites) and the include() or require() is taking a long time to process, consider using fsockopen() to grab the file instead of waiting for the include(). This only works well if the include()/require() is slow but the remote script executes fast. <?php $fp = fsockopen ("remote.server.com", 80, $errno, $errstr, 30); if (!$fp) { echo "Can't fetch remote data: $errstr ($errno)\n"; } else { fputs ($fp, "GET /path/to/page.php\r\n"); $doit = 0; while (!feof($fp)) { $thing = fgets ($fp,128); if(substr($thing, 0, 10) == "<!--tag-->") $doit = 1; if($doit == 1) echo $thing; } fclose ($fp); } ?> At the top of page.php, add the HTML comment line <!--tag--> so that the script will work correctly. The tag line is used to denote the end of the HTTP headers and the beginning of the actual HTML output. This will still process the script remotely, so it is ideal for sharing small pieces of data between sites (such as a poll) without needing to share the database(s). Be careful when doing this with large or complex scripts, as you will chew up CPU cycles quickly by waiting for the socket to finish. Hope someone finds this useful. -- http://www.php.net/manual/en/function.include.php http://master.php.net/manage/user-notes.php?action=edit+31486 http://master.php.net/manage/user-notes.php?action=delete+31486 http://master.php.net/manage/user-notes.php?action=reject+31486

« previous php.notes (#46990) next »