Jump to content

Shared memory, semaphore php help please!


abhijit.sharma

Recommended Posts

Hi Guys,

 

I am facing great problem, have tried different methods now I m completely annoyed  :'(.

 

I want to maintain the location on the memory accessed by all the sessions

 

I am working on some application where I m suppose to make communication among sessions. So I though of using semaphore(shared memory with mutual exclusion) in PHP.

 

 

 

I don't know why the script always create new memory location with same key  when ever I open the page, instead it should maintain the pointer, with the value.

 

In example below, when ever I change the value for location "1234"(shmop_open(1234, "c", 0644, 1)) still the value remains one or I think php creates new location have same key("1234") with value one. 

 

I think when ever I open the page it creates new thread, and every thread creates new location on the memory. I dont know how to stop this.

 

Example:

<?php

 

$shm_id = shmop_open(1234, "c", 0644, 1);

 

 

if(!$shm_id)

{

    echo "Error while creating the shared memory segment.\n";

}

else

{

echo "Memory created";

}

$shm_bytes_written = shmop_write($shm_id, "1", 0);

 

if($shm_bytes_written != strlen("1"))

{

    echo "Error while writing data\n";

}

 

$my_string = shmop_read($shm_id, 0, 1);

echo "....Value.... =". $my_string;

shmop_close ( $shm_id );

?> 

 

(I can provide you with my attachment) please go through this.

 

 

Thanks

-Abhijit

 

 

Your help and new ideas will be appreciated.

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/184264-shared-memory-semaphore-php-help-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.