All posts in PHP

Captura-phpinfo-2528-2529-2B-2BGoogle-2BChrome-1

I finalment, instal·lem PHP. Al tractar-se d’una màquina de desenvolupament, instal·larem PHP 5.4 Release Candidate 1 i així podrem provar les noves opcions de PHP 5.4 com els traits per a evitar algunes limitacions de les herències úniques pròpies de PHP. Aquestes novetats s’integraran properament a l’IDE NetBeans.

Recuperarem el codi font de PHP:

svn checkout https://svn.php.net/repository/php/php-src/branches/PHP_5_4 php-src-5.4

Preparem llibreries i programes que necessitem per a crear el PHP 5.4 com a mòdul per a l’Apache instal·lat a l’apartat 3 d’aquesta sèrie.

apt-get install aspell curl libaspell-dev libbz2-dev libc-client-dev libcurl4-openssl-dev libfreetype6 libfreetype6-dev libjpeg62 libjpeg62-dev libmcrypt4 libmcrypt-dev libmhash2 libmhash-dev libming-dev libmysqlclient15-dev libncurses-dev libpng3 libpng12-dev libpspell-dev libreadline-dev libsasl2-dev libsnmp-dev libt1-5 libt1-dev libtidy-dev libxml2 libxml2-dev libxml2-utils libxpm4 libxpm-dev libxslt1-dev make build-essential autoconf bison

Configurem el PHP

cd php-src-5.4

./buildconf

./configure --with-apxs2=/usr/bin/apxs2 --disable-short-tags --with-openssl --with-zlib --enable-bcmath --with-bz2=/bin/bzip2 --enable-calendar --with-curl --with-curlwrappers --enable-exif --enable-ftp --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-xpm-dir=/usr/lib --with-t1lib --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-imap --with-imap-ssl --with-ldap --with-ldap-sasl --enable-mbstring --with-mcrypt --with-mhash --with-ibm_db2=/opt/ibm/db2/V9.7 --with-pspell --with-readline --with-snmp --enable-soap --enable-sockets --with-tidy --enable-wddx --with-xmlrpc --with-xsl --enable-zip --with-pear --with-kerberos

I procedim a compilar, en una màquina amb 4GB de RAM i 2 processadors a 2,6GHz hem trigat 16 minuts.

make && make install

Instal·lem el php.ini preparat per a desenvolupament

cp php.ini-development /usr/local/lib/php.ini

Instal·lem el mòdul ibm_db2


pecl install ibm_db2

Indicant /opt/ibm/db2/V9.7 com a carpeta on tenim instal·lat el DB2, o allà on pertoqui.

afegim la secció ibm_db2 al php.ini

extension=/usr/local/lib/php/extensions/no-debug-zts-20100525/ibm_db2.so
ibm_db2.instance_name=db2inst1

Arrenquem l’apache

/etc/init.d/apache2 restart

I certifiquem que funciona fent

echo "" > /var/www/index.php
rm /var/www/index.html

I obrint un navegador que apunti al servidor obtindrem

Si volem tenir també opcions de MySQL:

./configure --with-apxs2=/usr/bin/apxs2 --disable-short-tags --with-openssl --with-zlib --enable-bcmath --with-bz2=/bin/bzip2 --enable-calendar --with-curl --with-curlwrappers --enable-exif --enable-ftp --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-xpm-dir=/usr/lib --with-t1lib --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-imap --with-imap-ssl --with-ldap --with-ldap-sasl --enable-mbstring --with-mcrypt --with-mhash --with-ibm_db2=/opt/ibm/db2/V9.7 --with-pspell --with-readline --with-snmp --enable-soap --enable-sockets --with-tidy --enable-wddx --with-xmlrpc --with-xsl --enable-zip --with-pear --with-kerberos --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

IBM-2Blogo-2Bvintage

En aquesta sèrie de posts explicaré com instal·lar una màquina blava, una particular manera de celebrar el centenari d’IBM, amb l’IBM HTTP Server, IBM DB2 i PHP 5.4 en un Ubuntu Server 10.04 LTS de 64 bits.

D’ençà la versió 6.0 de l’IHS (IBM Http Server) aquest producte només s’instal·la amb el WAS (WebSphere
Application Server). Per a fer-ho des del servei de paqueteria d’ubuntu, editarem l’arxiu /etc/apt/sources.list i descomentarem els reposioris partner :

deb http://archive.canonical.com/ubuntu lucid partner

I actualitzem:
sudo apt-get update


Procedim a instal·lar el paqet WAS CE Community Edition, d’utilització lliure de pagament i més lleguer.

sudo apt-get install wasce-server

I bé, ja el tenim instal·lat, comprovem l’status del servidor
sudo /etc/init.d/wasce-server status
* Websphere CE is running

Però no el veiem operatiu!
Executant el que fa l’start de wasce-server des de root, veiem que es triga prop de quatre minuts en arrencar, en una màquina amb dos processadors i 4GB de RAM, així que és questió d’esperar-se fins accedir al WebSphere Application Server Community Edition pel port 8090 i accedir a la cònsola administrativa.

Usuari: system
Contrasenya: manager

No cal dir que s’ha de canviar anant al menú Security/Users and Groups.
Captura-php-architect-253A-October-2010-1

Al número d’octubre de la revista php|architect hi ha un interessant article sobre PHP i IBM i (AS/400)

IBM and Zend have pushed hard to prove that PHP on the IBM i is a viable solution, and it is. While they tend to gear most of their marketing toward mainframe developers to switch over to PHP, coming to the IBM i from a PHPers experience is a whole different matter. We know the language, just not this well-aged platform. IBM has done their best to make developers welcome but the environment is still different. I’ll go through some of the common annoyances of having to work on the i, as well as tips to make life easier. This is not an introduction to programming on the i, just tips to make your life easier. –by Chris Tankersley

by Alex Woodie from http://www.itjungle.com/tfh/tfh092611-story02.html
IBM i shops that were hesitant to deploy pre-packaged PHP apps on the platform because of the end of MySQL support from Oracle can go forward with their plans now thanks to the public unveiling of Zend DBi, a new IBM i-specific version of MySQL that Zend Technologies will develop, maintain, and support. Zend DBi is slated to ship with the upcoming December release of the Zend PHP software stack for the IBM i server, the company said last week.
Ever since Oracle announced plans to drop MySQL support for i5/OS V5R4 and IBM i 6.1 last December, IBM and Zend have been working to figure out a way to keep the open source database alive on the platform. MySQL is a critical piece of the PHP puzzle, since the majority of pre-packaged PHP applications (such as SugarCRM, Joomla, and Drupal) were designed to use MySQL. Developers writing new PHP apps aren’t affected as much, as they can hit the DB2/400 database directly.
The solution to the problem became evident last week when Zend officials shared details of the forthcoming Zend Server 5.5 for IBM i release, which is expected to become generally available in December. The new PHP stack will contain Zend DBi, which Zend’s IBM alliance director Michael Scarpato calls a “drop in replacement” for the old release of MySQL for IBM i.
Scarpato on Friday outlined for IT Jungle the current state of MySQL on IBM i support and the plans for making Zend DBi the second officially supported database for the platform. “The status quo at the moment is fine. We ship MySQL as part of Zend Server for 5.1. It’s still available from the Oracle website,” he says.
“The question in the minds of folks in the i community who rely on MySQL is, ‘Who’s going to take care of it as it goes forward?’,” Scarpato asked rhetorically. “So as problems emerge in the code, or as security fixes need to be applied, or if there’s some killer new feature that comes out for other platforms that is very relevant for the i platform as well, how do we get that over? Who’s going to take care of that? It’s an open source project. So anybody could do it. But who’s really going to take responsibility to care and feed it, and then make commercial support available for the community who would like it? So that’s going to be Zend.”
The initial release of Zend DBi will be, for all intents and purposes, functionally identical to the last supported MySQL for IBM i release to come out of Oracle, even if the actual code isn’t quite the same. Zend hasn’t finished porting it over, so it’s impossible to say how much the code bases will look alike. But the plan going forward is for Zend DBi to diverge from the last supported version of MySQL from Oracle, Scarpato says.
Any changes that Zend makes will be posted back to the MySQL open source project, as per the terms of the GNU GPL license that both MySQL and Zend DBi are distributed under. However, there are currently no plans to make Zend DBi an open source project in its own right, Scarpato says. No beta releases of Zend DBi are planned.
Zend is putting in a lot of work to port Oracle’s MySQL source code to IBM i, says Allison Butterill, the Power Systems application development offering manager at IBM. “Oracle provides source code on its website, and anybody can download and create binaries, but it’s nowhere close to a trivial task,” she says. “Zend is taking that on and will use that code for MySQL as the base for what they’re going to provide with Zend DBi.”
IBM will continue to develop the IBMDB2i storage engine, which enables PHP applications that use MySQL to actually store data in DB2/400. A new release of the storage engine that works with Zend DBi will be available with Zend Server 5.5 for IBM i in December.
Besides the new database, Zend Server 5.5 for IBM i will also mark the general availability of the new open source XML Toolkit that Zend and IBM have co-developed. The new toolkit, which we first covered in April, was designed to do a better and more transparent job of connecting PHP applications with existing IBM i programs and services. The old toolkit, which was developed by AURA Equipments, will continue to work with Zend Server 5.5, even though it’s not distributed as part of the new PHP stack, Zend’s senior director of product management Kent Mitchell says.
The new IBM i release of Zend Server 5.5 will bring several other enhancements that have been available for Windows and Linux users for several months. Zend says these include new deployment and IT automation features that will help ease the handoff of PHP applications from development to operations teams, as well as new application delivery functions and automated scaling of enterprise PHP applications.
The new stuff–Zend DBi, the XML Toolkit, and Zend Server 5.5 functions–will be discussed in great detail at the forthcoming ZendCon 2011 conference, which is scheduled for October 17 through 20 in Santa Clara, California. Zend has devoted an entire track to PHP on IBM i topics. PHP on IBM i pros who will be presenting at ZendCon include Mike Pavlak, Alan Seiden, Tony Cairns, and Tim Rowe.
For more information on ZendCon 2011, see www.zendcon.com.

PHP 5.2 discontinued

Categories: PHP
Comments: No

Good news for the PHP community, Johannes Schlüter says:

All PHP users should note that the PHP 5.2 series is NOT supported
anymore. All users are strongly encouraged to upgrade to PHP 5.3.8.

If you are currently in 5.2 and plans to go to 5.3, read the Migrating guide… previously :)

Why is a good choice upgrade to 5.3.x?

  • Support for namespaces
  • Late static binding
  • Lambda Functions and Closures
  • Syntax additions: NOWDOC, ternary short cut “?:” and jump label (limited goto), __callStatic()
  • Under the hood performance improvements
  • Optional garbage collection for cyclic references
  • Optional mysqlnd PHP native replacement for libmysql
  • Improved Windows support including VC9 and experimental X64 binaries as well as portability to other supported platforms
  • More consistent float rounding
  • Deprecation notices are now handled via E_DEPRECATED (part of E_ALL) instead of the E_STRICT error level
  • Several enhancements to enable more flexiblity in php.ini (and ini parsing in general)
  • New bundled extensions: ext/phar, ext/intl, ext/fileinfo, ext/sqlite3, ext/enchant
  • Over 140 bug fixes and improvements to PHP, in particular to: ext/openssl, ext/spl and ext/date
  • Added “max_file_uploads” INI directive, which can be set to limit the number of file uploads per-request to 20 by default, to prevent possible DOS via temporary file exhaustion.
  • Added missing sanity checks around exif processing.
  • Fixed a safe_mode bypass in tempnam().
  • Fixed a open_basedir bypass in posix_mkfifo().
  • Improved LCG entropy. (Rasmus, Samy Kamkar)
  • Added a 3rd parameter to get_html_translation_table. It now takes a charset hint, like htmlentities et al.
  • Methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn’t affect non-namespaced classes.
  • Added ability to connect to HTTPS sites through proxy with basic authentication using stream_context/http/header/Proxy-Authorization.
  • Added options to debug backtrace functions.
  • Fixed bug #54939 (File path injection vulnerability in RFC1867 File upload filename). Reported by Krzysztof Kotowicz. (CVE-2011-2202)
  • And more Key and Security Enhancements and Fixes.

    NetBeans-IDE-7.0

    NetBeans IDE 7.0 features the following changes:
    • Introduction of JDK 7 support including editor enhancements (syntax, hints)
    • Revamped support for WebLogic Application Server and GlassFish 3.1
    • Oracle Database improvements
    • HTML5 editing support
    • Maven 3 is supported and bundled with the IDE
    • Improved support for CDI, REST services, Java Persistence, and Bean Validation
    • PHP Rename Refactoring
    • Line wrapping
    • Improved detection of external changes (native file system listening)
    • Updates to the C/C++ support (remote file system browsing, library projects running/debugging, enhanced templates/specializations)
    • Support for Git 1.7.х
    • Additional enhancements are listed at the NetBeans IDE 7.0 New and Noteworthy page

    Code
    Description
    I5_ERR_OK 
    0
    No error.
    I5_ERR_ERROR  
    1
    Error occurred
    I5_ERR_TOOMUCHOPENFILE 
    2
    Too many open files
    I5_ERR_MEMALLOC 
    3
    Not enough memory
    I5_ERR_INVALIDPTR 
    4
    Invalid pointer (handle); specific message
    I5_ERR_FILENOTFOUND 
    5
    File not found
    I5_ERR_FIELDNOTFOUND 
    6
    Field not found
    I5_ERR_INVALIDFIELDNBR 
    7
    Field number invalid
    I5_ERR_INVALIDKEYLEN 
    8
    Wrong key length
    I5_ERR_INVALIDKEYNBR 
    9
    Wrong key field number
    I5_ERR_NOTENABLETOUPDATE 
    10
    File not allowed to be changed
    I5_ERR_INVALIDOPENMODE 
    11
    File open mode not valid for operation
    I5_ERR_RECORDNOTFOUND 
    12
    Record not found
    I5_ERR_RECORDLOCKED 
    13
    Record locked
    I5_ERR_BEOF 
    14
    End or begin of file reached
    I5_ERR_FILELIMITS 
    15
    Reads out of the file (before or after EOF)
    I5_ERR_NOTCONNECTED 
    16
    Not connected
    I5_ERR_INVALIDSEQ 
    17
    Operation sequence not valid
    I5_ERR_NORANGESET 
    18
    Range not defined
    I5_ERR_NOLINKDEFINED 
    19
    Link not defined
    I5_ERR_NOCURRENTRECORD 
    20
    No current record
    I5_ERR_NULLNOTALLOWED 
    21
    Null operation not applicable (field does not support nulls)
    I5_ERR_BADSESSION 
    22
    AS/400 session not valid
    I5_ERR_WRONGLOGIN 
    23
    Bad login user or password
    I5_ERR_NOTENOUGHRIGHTS 
    24
    User rights problem
    I5_ERR_INVALIDTYPE 
    25
    INVALID TYPE
    I5_ERR_INVALIDINFO 
    26
    Info variable height not enough
    I5_ERR_NOTTYPEPROPERTY 
    27
    Bad property ID
    I5_ERR_RECORDCHANGED 
    28
    The record has changed before update
    I5_ERR_ALLREADYINTRAN 
    29
    Allready in a transaction (nested transaction are not supported)
    I5_ERR_NOTINTRAN 
    30
    Not in a transaction
    I5_ERR_INCORRECTVALUE 
    36
    unable to set the value (out of range; …)
    I5_ERR_PARAMNOTFOUND 
    37
    Requested parameter does not exist in the description.
    I5_ERR_ENDOFOCC 
    38
    Number of occurences greater than the maximum set in the description.
    I5_ERR_DESC_UNEXP 
    39
    Unexpected error while processing description
    I5_ERR_DQDESC_UNSUPP 
    40
    Unsupported description for a data queue
    I5_ERR_DESC_WRONG_DATAOP 
    41
    Wrong operation on a data field of a description
    I5_ERR_PARSEXML 
    42
    Internal error; please contact Aura Equipement; error number 42
    I5_ERR_PHP_HDLDFT 
    256
    No default connection found.
    I5_ERR_PHP_HDLCONN 
    257
    This resource has no connection active.
    I5_ERR_PHP_HDLBAD 
    258
    Bad connection handle
    I5_ERR_PHP_OPTIONSTYPE 
    259
    The type of ” I5_OPTIONS_ALIAS” option must be x and not x
    I5_ERR_PHP_OPTIONSNUMBER 
    260
    Option number -1 is unknown.
    I5_ERR_PHP_RESOURCE_BAD 
    261
    No resource found .
    I5_ERR_PHP_TYPEPARAM 
    262
    Type of element x in parameter -1 must be y. Type z was provided.
    I5_ERR_PHP_NBPARAM_BAD 
    263
    Wrong parameter count
    I5_ERR_PHP_TYPEGET 
    264
    The x function is unable to translate this type (-1).
    I5_ERR_PHP_OPERATOR_BAD 
    265
    Unknown operator (x)
    I5_ERR_PHP_BAD_LEN_PROP 
    266
    The length of the property x is too large; -2 instead of -3 max.
    I5_ERR_PHP_LIST_PROP 
    267
    This element 0¡ is not accepted.
    I5_ERR_PHP_SPOOL_FILE_FOPEN 
    269
    Internal Error on tempory file(x); code error : -1.
    I5_ERR_PHP_API_LENGTH 
    270
    The length of element -1 of parameter is too big (max : -2).
    I5_ERR_PHP_BAD_TYPE_KEYNAME 
    271
    The name property n°-1 must be a string.
    I5_ERR_PHP_BOOKMARK 
    272
    Bookmark value expected for this operator
    I5_ERR_PHP_NOT_BOOKMARK 
    273
    Bookmark value unexpected for this operator
    I5_ERR_PHP_CALL_BINDPARAM 
    274
    The I5_bind_result function can be called only once
    I5_ERR_PHP_GETPARAM 
    275
    specific message
    I5_ERR_PHP_BINDPARAM 
    276
    Internal error; please contact Aura Equipement; error number 276
    I5_ERR_PHP_PARAM_DESC 
    277
    specific message
    I5_ERR_PHP_BLOBSIZE 
    278
    the blob size received(-1) is different of the announced size(-2).
    I5_ERR_PHP_SEEK_FIRSTLAST 
    279
    Bookmark value expected for this operator
    I5_ERR_PHP_PROPERTY_NUMBER 
    280
    This(-1) property number is not valid.
    I5_ERR_PHP_VARIABLE 
    281
    You can’t use the I5_bind_param function and specify parameters
    I5_ERR_PHP_BAD_ADDNEW_CST 
    282
    The only constant accpeted are I5_ADDNEW_NOCLEAR or I5_ADDNEW_CLEAR.
    I5_ERR_PHP_NOT_RPIVATE_CONNECTION 
    283
    The restore connection is not allowed.
    I5_ERR_PHP_ALREADY_PGMNAME 
    284
    You cannot call this function; because it was already called or x was called.
    I5_ERR_PHP_PRIVATE_CONNECTION_NOT_FOUND 
    285
    the -1 connection has not been found.
    I5_ERR_PHP_LOCALHOST_NOT_PERMIT 
    286
    you must specify the AS/400 address
    I5_ERR_PHP_INTERNAL 
    288
    Internal error; please contact Aura Equipement; error number 288
    I5_ERR_PHP_EXECUTE 
    289
    You cannot read a request with parameters without calling the I5_execute function.
    I5_ERR_PHP_NO_COMMAND 
    290
    Empty command line or name
    I5_ERR_PHP_EMPTY_ARRAY 
    291
    Internal error; please contact Aura Equipement; error number 291
    I5_ERR_PHP_NO_KEYNAME 
    292
    Unspecified name for array item -1.
    I5_ERR_PHP_NO_PARMNAME 
    293
    Internal error; please contact Aura Equipement; error number 293
    I5_ERR_PHP_NO_ZVALUE 
    294
    Internal error; please contact Aura Equipement; error number 294
    I5_ERR_PHP_COMMAND_ERROR 
    295
    The command returned an error: x.
    I5_ERR_PHP_DATAREA_READ 
    296
    The command returned an error: x.
    I5_ERR_PHP_GET_SYSVAL 
    297
    The command returned an error: x.
    I5_ERR_PHP_UNAVIABLE_PASE 
    298
    This feature is not available on i5/OS environment.
    I5_ERR_PHP_ELEMENT_MISSING 
    304
    An element of the array has a wrong type within function_name(type) function.
    I5_ERR_PHP_BAD_DEF 
    305
    You cannot define an occurence number; and an occurence reference for the same parameter -1.
    I5_ERR_PHP_BAD_KEYNAME 
    306
    Name x is not a property name for a program description
    I5_ERR_PHP_NO_DS_VALUE 
    307
    You cannot set a value for ‘Data Structure’ x.
    I5_ERR_PHP_BAD_DS_INPUT 
    308
    Values for ‘Data Structure’ parametre -1 does not match the description.
    I5_ERR_PHP_DTAQ_BADKEY 
    309
    The key is not correct.
    I5_ERR_PHP_DESC_EMPTY 
    310
    The description array is empty.
    I5_ERR_PHP_BAD_PROG_NAME 
    311
    Program not found.
    I5_ERR_PHP_AS400_MESSAGE 
    312
    Internal error; please contact Aura Equipement; error number 312
    I5_ERR_PHP_NOT_DTAQ_KEY 
    313
    No key defined.
    I5_ERR_PHP_EMPTY_NAME 
    314
    Object name can not be empty
    I5_ERR_PHP_BAD_DTAARA_LENGTH 
    315
    Data area x should be from -1 to -2
    I5_ERR_PHP_EMPTY_PCML 
    316
    PCML can not be empty
    I5_ERR_PGM_DONT_EXIST 
    530
    Internal error; please contact Aura Equipement; error number 530
    I5_ERR_FIELDNULL 
    4097
    Field value is NULL
    IBM_i

    Zend is pleased to announce the availability of Zend Server for IBM i 5.1. This release includes significant improvements to performance and stability, as well as the following:

    • PHP 5.2 packages upgraded to 5.2.17
    • PHP 5.3 packages upgraded to 5.3.6
    • Zend Framework packages upgraded to 1.11.3
    • New Zend Server RESTful Web API
    • Native IBM i support for Oracle database drivers
    • New PHP Toolkit (beta)
    • Improvements to Zend Monitor
    • Improvements to Zend Job Queue
    • Security and other bug fixes

    A partir de la versió 4.1 de MySQL va canviar el mètode de creació de contrasenyes, la funció PASSWORD() retorna una cadena molt més gran i segura amb una encriptació unidireccional.

    Si des de PHP volem generar una contrasenya validable des de MySQL ens dotarem d’aquest mètode:


    /**
    * Retornem una cadena entenedora per la funció PASSWORD()
    * de MySQL
    *
    * @see http://php.net/manual/en/function.sha1.php
    * @see http://dev.mysql.com/doc/refman/5.1/en/encryption-functions.html#function_password
    * @param string $pwd
    * @return string
    */
    protected function mySqlPassword($pwd)
    {
    return "*" . strtoupper(sha1(sha1((string) $pwd,true)));
    }

    Les funcions de memòria compartida que suporta el PHP són una bona manera de gestionar indicadors de les aplicacions a nivell de sistema.

    Es tracta d’una manera de tenir variables superglobals, és a dir, consultables per tots els scripts de l’aplicació. Realment el que estem fent és accedir directament a blocs de memòria del servidor, convenientment reservat i assegurat.

    L’alternativa a aquesta gestió d’indicadors en memòria compartida són els tradicionals accessos al filesystem amb arxius semàfors.

    Però si la gestió d’aquesta memòria ens resulta fartosa, sobretot per haver de fer sempre un shmop_read() i controlar l’error per saber si una posició està ocupada o lliure, si el PHP s’executa en un servidor Linux, podem fer servir les funcions semàfor que faciliten la programació amb aquesta tècnica.

    shm_attach
    La instrucció shm_attach ens permet tractar els segments de memòria amb una facilitat tant gran que a cops sembla que estiguem tractant amb arxius tipus semàfor.

    Per reservar un segment executarem:
    $this->seg = shm_attach(0xCAFE, 1024, 0750);

    El primer paràmetre és l’id de segment de memòria amb el que volem treballar. En aquest exemple fem servir un de proves, però en explotació podríem fer servir la funció ftok(__FILE__), si aquest segment el reservem per a tota l’aplicació des d’un únic arxiu, o ftok(‘/etc/app/myapp.ini’) on indiquem la ruta de l’arxiu que conté la configuració per a l’aplicació i que s’estima únic per a la mateixa aplicació.

    El segon paràmetre és la mida en bytes d’aquest segment, reservem un KB. Cal tenir en compte a l’hora de dimensionar segments, que PHP a hores d’ara encara no és un llenguatge nativament UTF-8.

    El tercer paràmetre estableix els permisos d’aquest segment en format octal. Per omissió és 0666, però com que no volem que cap altre usuari del sistema que no sigui l’Apache, els del seu grup puguin llegir-ho, però la resta ni pugui conèixer la seva existència, establim permisos 0750.

    shm_put_var
    La instrucció shm_put_var serveix per a establir un valor a un slot del segment reservat.
    shm_put_var($this->seg, (int) $clau, $valor);

    El primer paràmetre és l’id del segment.

    El segon, l’slot del segment que volem declarar.

    El tercer, és el valor pròpiament dit.

    shm_get_var
    La instruccio shm_get_var serveix per a recuperar un valor d’un slot del segment reservat.
    if (shm_has_var($this->seg, $clau))
    {
    return shm_get_var($this->seg, (int) $clau);
    }

    El primer paràmetre és l’id del segment.

    El segon, l’slot del segment que volem recuperar. Podem fer servir shm_has_var per tractar d’esbrinar prèviament si està declarat o no aquest slot.

    Benchmark
    Les proves de rendiment que hem fet comparant aquesta tècnica amb accessos a arxius tipus semàfor al filesystem ens han reportat una mitjana de 60 cops més ràpid l’accés a memòria compartida, que a arxius del filesystem tant per a l’establiment de variables, com per a la recuperació d’aquestes.

    Una dada a tenir en compte!