A program to test shared memory in linux

Source: Internet
Author: User
1share. php allocate/delete shared memory? Phpif ($ stop! 1) {// Determine whether $ shm_id @ shmop_open (0xff3, a, 0644,100) has been created; if ($ shm_id) {echo memory block has been created \ n; exit ();} // create a 100-byte shared memory block identified as 0xff3 $ shm_id @ shmop_open 1 share. allocate/delete shared memory in php






If ($ stop! = 1)

{

// Determine whether a file has been created

$ Shm_id = @ shmop_open (0xff3, "a", 0644,100 );

If ($ shm_id ){

Echo "memory block created \ n ";

Exit ();

}

// Create a 100-byte shared memory block identified as 0xff3

$ Shm_id = @ shmop_open (0xff3, "c", 0644,100 );

If (! $ Shm_id ){

Echo "shared memory block creation failed \ n ";

}



// Write some content

For ($ I = 0; $ I <10; $ I ++)

{

$ Shm_bytes_written = shmop_write ($ shm_id, "shared block $ I", ($ I * 10 ));

}

Echo "created successfully ";

Shmop_close ($ shm_id );

}

Else

{

// Existence

$ Shm_id = @ shmop_open (0xff3, "a", 0644,100 );

If (! $ Shm_id ){

Echo "shared memory block \ n not found ";

Exit ();

}

// Delete

If (! Shmop_delete ($ shm_id )){

Echo "failed to delete .";

}

Shmop_close ($ shm_id );

Echo "memory block deleted! ";

}

?>



2. 2.php is used to display shared memory content.






// Open the shared memory block 0xff3

$ Shm_id = @ shmop_open (0xff3, "a", 0644,100 );

If (! $ Shm_id ){

Echo "shared memory block \ n cannot be enabled ";

Exit ();

}



// Read the content

$ My_string = shmop_read ($ shm_id, 0, $ shm_size );

If (! $ My_string ){

Echo "no content or cannot read \ n ";

}

Echo $ my_string. "\ n ";

Shmop_close ($ shm_id );

? & G

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.