Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6538245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:42:49+00:00 2026-05-25T10:42:49+00:00

The php code is supposed to read the shared memory I create in a

  • 0

The php code is supposed to read the shared memory I create in a C program below. However, I am reading all 0s no matter what I set the values in the shared memory to.
php code:

<?php
    $shm_id = shmop_open(9875, "a", 0, 0);
    echo "shmid=".$shm_id."    ";
    echo "size=".shmop_size($shm_id). " ";
    $shm_data = shmop_read($shm_id, 0, 8);
    if($shm_data == FALSE) 
        echo "failed to read"; 
    else
    {
        echo "data=";
        for($i=0;$i < 8;$i++)
        {
            echo $shm_data[$i];
            if($shm_data[$i] == 1)
                echo "1";
            else if($shm_data[$i] == 0)
                echo "0";
            else echo "v";
        }
    }
    shmop_close($shm_id);
    ?> 

The C code creates the shared memory block of size 8 bytes.

I have this code to create the shared memory block. I pass in a key of 9875, which I use in the php code.
C Code:

buf1 = allocArray_shared(8, sizeof(unsigned char), &shmid, 9875);
for(i = 0; i < 8; i++)
{
      buf1[i] = 0xFF;
}

void* allocArray_shared(int elementCount, int elementByteSize, int* shmid, key_t key)
{
    //size of entire array(cols*rows* byte size + row pointers)
    int array_size = elementByteSize * elementCount;


    //Allocate enough space for all elements + row pointers
    *shmid = shmget(key, array_size, 00666 | IPC_CREAT);

    char * arr = (char*)shmat(*shmid, NULL, 0);
    if(!arr) return NULL;



    //Return the pointer to the first row pointer
    return (void*)arr;
}

I checked that the C program is creating the shared memory region with ipcs command and it is there with the correct key value and the shmid value that gets returned from shmget. I also initialize the data to all 0xFF.

The php program successfully opens the shared memory region, and the shmid is always printed as 2, which does not match the shmid generated by shmget(does this matter, or does php map that to the correct shmid?).

The data in $shm_data is printed as all 0’s, while it should be 0xFF!!

Any tips on getting this working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:42:49+00:00Added an answer on May 25, 2026 at 10:42 am

    I give credit to Marc B and Joshua for answering my question.

    The main issue was that 0xFF was not a valid value and also I was not comparing values with the correct operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the PHP code below. It is supposed to select up to ten
The following code supposed to add at the beginning of my php files on
I'm looking for an algorithm (or PHP code, I suppose) to end up with
This PHP code... 207 if (getenv(HTTP_X_FORWARDED_FOR)) { 208 $ip = getenv('HTTP_X_FORWARD_FOR'); 209 $host =
The following PHP code snippet uses GD to resize a browser-uploaded PNG to 128x128.
I am running following PHP code to interact with a MS Access database. $odbc_con
I am using following PHP code to connect to MS Access database: $odb_conn =
Say i have this PHP code: $FooBar = a string; i then need a
I'm refactoring some PHP code and discovered that certain nested combinations of if ()
I am writing PHP code where I want to pass the session id myself

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.