note 97170 added to function.shm-put-var
| From: | orwellophile at spamtrak dot org | Date: | Tue, 06 Apr 2010 11:17:02 +0000 |
| Subject: | note 97170 added to function.shm-put-var | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167724@lists.php.net to get a copy of this message | ||
Quote: "Will it ever support resource identifiers like pfsockopen() pointers ... we run PHP as
a Apache Module ... no way to have true persistent sockets"
Sorry, but that doesn't make sense to me... the socket is still persistent, if you wish to
resume it, simply call pfsockopen() with the same host and port - and you will get the same socket.
There is no need to pass the actual resource variable.
If there is something amazingly special and unique about each socket, you can do the following - and
this should apply to any persistent resource:
To differentiate between or obtain a specific resource - simply serialize/store an index of each
resource's unique ID, along with the particulars that make that resource unique.
You can get a unique resource identifier as an integer value like so:
<?php
$rid = str_replace("Resource id #", "", print_r($fp, true));
// $rid = 2
?>
As pfsockopen() uses the hostname and port as a unique key to resume a persistent connection, you
can add a DNS wildcard, or a number of manual entries in /etc/hosts (or windows equiv.) as follows:
resource-0.host.com 192.168.100.1
resource-1.host.com 192.168.100.1
resource-2.host.com 192.168.100.1
resource-3.host.com 192.168.100.1
Then, after consulting your serialized list of resources, you can connect to a specific resource by
using it's resource id.
eg: $pf = pfsockopen("resource-$rid.host.com", $port, $timeout);
The new resource will be identical to the original in every way.
For file based stream resources you could do something similar with symlinks, or use the next
method...
For URL based or other resources with "paths" (I don't know if there *are* persistent
functions that involve such things) you could differentiate between them with using extraneous
information in the path. eg:
http://host.com/resource-4/../script.php
http://resource4@host.com/script.php
/tmp/././././file.txt
In the first example, the extraneous "resource-4" would be ignored by the webserver.
In the second, the superfluous username would be ignored by the webserver. (Something similar for
mysql_pconnect could be done with multiple usernames).
And in the the third example, four sequential occurrences of the "do nothing" string
"./" would indicate resource #4.
If this isn't enough, then you can use the fact that PHP shared memory resources are themselves
interoperable with those created by their .c counterparts. That allows you to write a thin .c
application to handle the dirty work.
Or you could attempt to reconnect to your own webserver, using persistent streams and the methods
outlined above, to achieve the end result. I can't think of an example of where something so
extreme would be necessary, but I'm sure it's not outside the realm of possibility.
I personally use an 117 MB binary database, which is stored in shared memory, both from the command
line (using a complied .c application), and from the web (via PHP, and
ftok()/shmop_open()/shmop_read()).
----
Server IP: 117.104.162.229
Probable Submitter: 124.190.249.142 (proxied: 124.190.249.142)
----
Manual Page -- http://www.php.net/manual/en/function.shm-put-var.php
Edit -- https://master.php.net/note/edit/97170
Del: integrated -- https://master.php.net/note/delete/97170/integrated
Del: useless -- https://master.php.net/note/delete/97170/useless
Del: bad code -- https://master.php.net/note/delete/97170/bad+code
Del: spam -- https://master.php.net/note/delete/97170/spam
Del: non-english -- https://master.php.net/note/delete/97170/non-english
Del: in docs -- https://master.php.net/note/delete/97170/in+docs
Del: other reasons-- https://master.php.net/note/delete/97170
Reject -- https://master.php.net/note/reject/97170
Search -- https://master.php.net/manage/user-notes.php