"Fossies" - the Fresh Open Source Software Archive

Member "hhvm-HHVM-4.166.0/hphp/test/zend/good/ext/shmop/tests/001.php" (8 Aug 2022, 1534 Bytes) of package /linux/www/hhvm-HHVM-4.166.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?hh <<__EntryPoint>> function main(): void {
    2 $hex_shm_id = 0xff3;
    3 $write_d1 = "test #1 of the shmop() extension";
    4 $write_d2 = "test #2 append data to shared memory segment";
    5 
    6 echo "shm open for create: ";
    7 $shm_id = shmop_open($hex_shm_id, "n", 0644, 1024);
    8 if (!$shm_id) {
    9   die("failed\n");
   10 } else {
   11   echo "ok\n";
   12 }
   13 
   14 echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n";
   15 
   16 echo "shm write test #1: ";
   17 $written = shmop_write($shm_id, $write_d1, 0);
   18 if ($written != strlen($write_d1)) {
   19   echo "failed\n";
   20 } else {
   21   echo "ok\n";
   22 }
   23 
   24 echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
   25 
   26 shmop_close($shm_id);
   27 
   28 echo "shm open for read only: ";
   29 $shm_id = shmop_open($hex_shm_id, "a", 0644, 1024);
   30 if (!$shm_id) {
   31   echo "failed\n";
   32 } else {
   33   echo "ok\n";
   34 }
   35 
   36 echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
   37 
   38 /* try to append data to the shared memory segment, this should fail */
   39 @shmop_write($shm_id, $write_d1, $written);
   40 
   41 shmop_close($shm_id);
   42 
   43 echo "shm open for read only: ";
   44 $shm_id = shmop_open($hex_shm_id, "w", 0644, 1024);
   45 if (!$shm_id) {
   46   echo "failed\n";
   47 } else {
   48   echo "ok\n";
   49 }
   50 
   51 echo "shm write test #1: ";
   52 $written = shmop_write($shm_id, $write_d2, $written);
   53 if ($written != strlen($write_d2)) {
   54   die("failed\n");
   55 } else {
   56   echo "ok\n";
   57 }
   58 
   59 echo "data in memory is: " . shmop_read($shm_id, 0, strlen($write_d1 . $write_d2)) . "\n";
   60 
   61 echo "deletion of shm segment: ";
   62 if (!shmop_delete($shm_id)) {
   63   echo "failed\n";
   64 } else {
   65   echo "ok\n";
   66 }
   67 
   68 shmop_close($shm_id);
   69 }