Outils pour utilisateurs

Outils du site


informatique:php:shared_memory

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
informatique:php:shared_memory [01/03/2010 18:20] cyrilleinformatique:php:shared_memory [19/05/2012 00:18] (Version actuelle) – modification externe 127.0.0.1
Ligne 32: Ligne 32:
  
 Création d'une block de mémoire partagée et remplissage avec plusieurs variables. Lecture de ce block et ces variables. Destruction du bloque de mémoire partagée. Création d'une block de mémoire partagée et remplissage avec plusieurs variables. Lecture de ce block et ces variables. Destruction du bloque de mémoire partagée.
-<code php> 
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
-<html> 
-  <head> 
-  <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
-  <title>Shared Memory - Essais01</title> 
-  <style type="text/css"> 
-  </style> 
-  </head> 
-<body> 
  
-<h1>Shared Memory - Essais01</h1> +[[/informatique/php/shared_memory/essais01|code source Essais01]]
-<ul> +
-  <li><a href="essais01.php?test=WRITER">WRITER</a></li> +
-  <li><a href="essais01.php?test=READER">READER</a></li> +
-  <li><a href="essais01.php?test=REMOVE">REMOVE</a></li> +
-</ul> +
- +
-<?php +
- +
-error_reporting(-1); +
- +
-$action = (isset($_GET['test']) && preg_match('/[a-z]{1,20}/i',$_GET['test']) ) ? $_GET['test'] : null ; +
-switch($action) +
-+
-  case 'WRITER': +
-    action_writer(); +
-    break; +
-  case 'READER': +
-    action_reader(); +
-    break; +
-  case 'REMOVE': +
-    action_remove(); +
-    break; +
-+
- +
-function getShmKey() +
-+
-  return ftok(__FILE__, 'A' ); +
-+
- +
-function action_writer() +
-+
-  echo 'WRITER:'; +
-  echo '<pre>'; +
-  $SHM_KEY = getShmKey(); +
-  $data =  shm_attach( $SHM_KEY, 1024, 0600); +
-  // plusieurs variables dans un même segment de mémoire. +
-  $test1 = array("hello","world","1","2","3"); +
-  $test2 = array("hello","world","4","5","6"); +
-  $test3 = array("hello","world","7","8","9"); +
-  shm_put_var( $data, 1, $test1); +
-  shm_put_var( $data, 2,$test2); +
-  shm_put_var( $data, 3,$test3); +
-  print_r(shm_get_var($data, 1)); +
-  print_r(shm_get_var($data, 2)); +
-  print_r(shm_get_var($data, 3)); +
-  shm_detach($data); +
-  echo '</pre>'; +
-+
- +
-function action_reader() +
-+
-  echo 'READER:'; +
-  echo '<pre>'; +
-  $SHM_KEY = getShmKey(); +
-  $data =  shm_attach( $SHM_KEY, 1024, 0666); +
-  print_r(shm_get_var($data, 1)); +
-  print_r(shm_get_var($data, 2)); +
-  print_r(shm_get_var($data, 3)); +
- shm_detach($data); +
-  echo '</pre>'; +
-+
- +
-function action_remove() +
-+
-  echo 'REMOVE:'; +
-  echo '<pre>'; +
-  $SHM_KEY = getShmKey(); +
-  $data =  shm_attach( $SHM_KEY, 1024, 0666); +
-  shm_remove($data); +
-  shm_detach($data); +
-  echo '</pre>'; +
-+
- +
-?> +
- +
-</body> +
-</html> +
- +
-</code>+
  
 ==== Essais02 ==== ==== Essais02 ====
Ligne 130: Ligne 41:
 Chez OVH c'est < 32Mo. Chez OVH c'est < 32Mo.
  
-<code php> +[[/informatique/php/shared_memory/essais02|code source Essais02]]
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +
-<html> +
-  <head> +
-  <meta http-equiv="content-type" content="text/html; charset=utf-8"> +
-  <title>Shared Memory - Essais01</title> +
-  <style type="text/css"> +
-  </style> +
-  </head> +
-<body> +
- +
-<h1>Shared Memory - Essais02</h1> +
-<ul> +
-  <li><a href="essais02.php?test=SEARCHMAXMEM">SEARCHMAXMEM</a></li> +
-</ul> +
- +
-<?php +
- +
-error_reporting(-1); +
- +
-$action = (isset($_GET['test']) && preg_match('/[a-z]{1,20}/i',$_GET['test']) ) ? $_GET['test'] : null ; +
-switch($action) +
-+
-  case 'SEARCHMAXMEM': +
-    action_searchmaxmem(); +
-    break; +
-+
- +
-function getShmKey() +
-+
-  return ftok(__FILE__, 'A' ); +
-+
- +
-function action_searchmaxmem() +
-+
-  echo 'SEARCHMAXMEM:'; +
-  echo '<pre>'; +
-  $SHM_KEY = getShmKey(); +
-  $size = 1024*1024 ; +
-  for( $i=0; $i<60; $i++) +
-  { +
-    $size=intval($size); +
-    if( $size==0 ) +
-      break; +
-    $data =  shm_attach( $SHM_KEY, $size, 0600); +
-    if( $data == null || $data === FALSE) +
-    { +
-      echo 'FAILED for size='.formatBytesSize($size)."\n"; +
-      break; +
-    } +
-    else +
-    { +
-      echo 'OK for size='.formatBytesSize($size)."\n"; +
-      shm_remove($data); +
-      shm_detach($data); +
-    } +
-    $size += 1024*1024 ; +
-  } +
-  echo '</pre>'; +
-+
- +
-/** +
- * @parame int $sizeInBytes +
- * @return string  +
- */ +
-function formatBytesSize( $sizeInBytes, $afterColon=2) +
-+
-    // less than 1kB +
-    if($sizeInBytes < 1024) +
-    { +
-        return $sizeInBytes . ' B'; +
-    } +
-    // between 1kB and 1MB +
-    if ($sizeInBytes >= 1024 && $sizeInBytes < 1048576) +
-    { +
-        return number_format( $sizeInBytes / 1024, $afterColon) . ' KB'; +
-    } +
-    // between 1MB and 1GB +
-    if ($sizeInBytes >= 1048576 && $sizeInBytes < 1073741824) +
-    { +
-        return number_format( $sizeInBytes / 1048576, $afterColon) . ' MB'; +
-    } +
-    // more than 1GB +
-    return number_format( $sizeInBytes / 1073741824, $afterColon) . ' GB'; +
-+
- +
-?> +
- +
-</body> +
-</html> +
-</code +
  
informatique/php/shared_memory.1267464051.txt.gz · Dernière modification : 19/05/2012 00:15 (modification externe)

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki