Shared memory between scripts ? shmop etc... help !

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patricio Stegmann

    Shared memory between scripts ? shmop etc... help !

    Hi,
    I am trying to develop a very basic but portable chat engine with php.
    I would like to develop it without any database or filesystem stuff,
    because I want it very portable and easy to install. So I was looking
    for a way to make scripts communicate, or keep a kind of state . So
    someone told me to look for shared memory operations... shmop_open and
    all this things.... but I cant seem to find a script that uses this,
    or something that works...
    I tried some examples (always same ones) on different phpsites, like
    creating a shmop object, writing on it then reading from it, all in
    the same script... what i would like to do is slightly different; have
    a writer page, and a reader page, then i could do some kind of chat
    ..... the writer page would be the textsubmitter stuff... the reader
    page would be an autoreloading page ... then with some simple
    parameters I could finalize a very simple chat, pluggable anywhere ...
    so ... When I do a write page, it works, but when I try to read, on
    another script, with for example this:

    <?
    $shm_id = shmop_open(0xff 3, "a", 0644, 100);
    echo $shm_id;
    ?>


    0xff3 being the place where i created on the wrietr page ... then i
    get:


    Warning: shmop_open(): unable to attach or create shared memory
    segment in /var/www/localhost/htdocs/chat/read.php on line 2



    So I dont understand why it doesn't work !

    Thanks for your attention


    Patricio Stegmann
  • Colin McKinnon

    #2
    Re: Shared memory between scripts ? shmop etc... help !

    Patricio Stegmann wrote:
    [color=blue]
    > another script, with for example this:
    >
    > <?
    > $shm_id = shmop_open(0xff 3, "a", 0644, 100);
    > echo $shm_id;
    > ?>
    >
    >
    > 0xff3 being the place where i created on the wrietr page ... then i
    > get:
    >
    >
    > Warning: shmop_open(): unable to attach or create shared memory
    > segment in /var/www/localhost/htdocs/chat/read.php on line 2
    >[/color]

    I'd recommend only every (re) creating the key using ftok(). But why are you
    bothering with shm at all? If you control both ends of the system on a
    Unix/Linux box there's very little overhead in using a real file.

    HTH

    C.

    Comment

    • Chung Leong

      #3
      Re: Shared memory between scripts ? shmop etc... help !

      "Patricio Stegmann" <kpoman@hotmail .com> wrote in message
      news:18ca5147.0 406230409.4bf87 f82@posting.goo gle.com...[color=blue]
      > Hi,
      > I am trying to develop a very basic but portable chat engine with php.
      > I would like to develop it without any database or filesystem stuff,
      > because I want it very portable and easy to install. So I was looking
      > for a way to make scripts communicate, or keep a kind of state . So
      > someone told me to look for shared memory operations... shmop_open and
      > all this things.... but I cant seem to find a script that uses this,
      > or something that works...
      > I tried some examples (always same ones) on different phpsites, like
      > creating a shmop object, writing on it then reading from it, all in
      > the same script... what i would like to do is slightly different; have
      > a writer page, and a reader page, then i could do some kind of chat
      > .... the writer page would be the textsubmitter stuff... the reader
      > page would be an autoreloading page ... then with some simple
      > parameters I could finalize a very simple chat, pluggable anywhere ...
      > so ... When I do a write page, it works, but when I try to read, on
      > another script, with for example this:
      >
      > <?
      > $shm_id = shmop_open(0xff 3, "a", 0644, 100);
      > echo $shm_id;
      > ?>
      >
      >
      > 0xff3 being the place where i created on the wrietr page ... then i
      > get:
      >
      >
      > Warning: shmop_open(): unable to attach or create shared memory
      > segment in /var/www/localhost/htdocs/chat/read.php on line 2
      >
      >
      >
      > So I dont understand why it doesn't work ![/color]

      Resources are freed automatically when a script terminates, duh!


      Comment

      Working...