Georg Hopp 18 years ago
parent
commit
c1606a4592
  1. 26
      ajax+json/test2.html
  2. 3
      libs/c_personAdmin.php
  3. 10
      libs/c_xmlify.php
  4. 61
      libs/mutualExclusion.php
  5. 6
      pvtest.php

26
ajax+json/test2.html

@ -0,0 +1,26 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>test</title>
<script type="text/javascript">
<!--
arr = new Array ();
arr['hallo'] = 'hallo';
arr[0] = 'du';
arr[19] = 'bla';
arr['trudel'] = 'fudel';
arr['31'] = 'glugsbla';
console.dir (arr);
console.log ('%d', arr.length);
for (a in arr)
console.log ('%s: %s', a, arr[a]);
-->
</script>
</head>
<body>
</body>
</html>

3
libs/c_personAdmin.php

@ -50,7 +50,8 @@ class c_personAdmin extends c_picToolSavant
unset ($this->dbHandle);
}
private function getPersons ()
//private function getPersons ()
function getPersons ()
{
$result = NULL;

10
libs/c_xmlify.php

@ -14,10 +14,10 @@ function xmlToVar ($xr)
! ($xr->nodeType == 15 &&
$xr->name == 'variable'))
{
print "[DEBUG:xmlToVar] " . $xr->nodeType . " / " . $xr->name .
" / " . $xr->value . "\n";
if ($xr->nodeType == 3 && $xr->hasValue == TRUE)
// der iconv is nur drin weil evolver ihre Seiten dummer weise
// als latin1 verschicken, aus der Datenbank aber utf-8 kommt.
$ret = iconv ("UTF-8", "ISO-8859-1", $xr->value);
$ret = $xr->value;
}
return $ret;
@ -34,6 +34,8 @@ function xmlToArray ($xr)
! ($xr->nodeType == 15 &&
$xr->name == 'array'))
{
print "[DEBUG:xmlToArray/1] " . $xr->nodeType . " / " . $xr->name .
" / " . $xr->value . "\n";
if ($xr->nodeType == 1 &&
$xr->name == 'item')
{
@ -43,6 +45,8 @@ function xmlToArray ($xr)
! ($xr->nodeType == 15 &&
$xr->name == 'item'))
{
print "[DEBUG:xmlToArray/2] " . $xr->nodeType . " / " . $xr->name .
" / " . $xr->value . "\n";
if ($xr->nodeType == 1)
{
switch ($xr->name)

61
libs/mutualExclusion.php

@ -1,10 +1,54 @@
<?php
/***************************************************************************
* This gives a method of mutual exclusion for critical Sections within
* your script. A lock-file will be created for every critical section that
* must be secured. The file hold information about the lock and is a
* handle (name) for the lock, so that every script uses the same lock.
* The lock will be achieved by one of two ways.
*
* 1. by using semaphores if they are available within the current php
* installation.
* 2. else by using flock, which exists within every php installation.
*
* Semaphores are used in favour because flock did not work reliably in
* threaded environments. That means, if we have no semaphores and are
* in a threaded environment these functions are also not reliable.
* In doubt ask your administrator or provider.
*
* Author: Georg Steffers <georg@steffers.org
* Date: 14th Oct. 2007
***************************************************************************/
require_once dirname(__FILE__) . '/../config.php';
require_once LIBDIR . 'errException.php';
function acquireLock ($lockFile, $csId)
/**
* Try to acquire a lock to enter a critical section. If the lock is already
* acquired the function blocks until the lock id freed again. If more than
* one process waits for the lock, than it is undefined which process get
* the lock next. This depends on which process gets CPU time first. All other
* processes continue waiting.
*
* Sideeffects:
* If this function succeeds ignore_user_abort is set to TRUE so that the
* critical section might not be interruped by a user abort. This can
* but shouldn't be changed within the critical section and will be reset
* in releaseLock.
*
* Arguments:
* $lockFile <string>: Path and basename to the lockfile to use.
* $csId <string[1]>: Id of the critical section, will be part of filename.
* $msg <string>: The message to be written to the lockfile.
*
* If $msg is NULL, a default message is created from session_id and time
*
* Returns:
* Array of lock information.
* [0] Filehandle to opened lockfile.
* [1] Resource id for semaphor
* [2] the old setting of ignore_user_abort.
*/
function acquireLock ($lockFile, $csId, $msg = NULL)
{
$fName = $lockFile . $csId . '.lck';
$lock = NULL;
@ -31,7 +75,9 @@ function acquireLock ($lockFile, $csId)
}
// Here one could write informations in the lockfile...time, pid, etc.
fwrite ($lockHandle, session_id () . '::' . time ());
if ($msg === NULL)
$msg = session_id () . '::' . time ();
fwrite ($lockHandle, $msg . "\n");
fflush ($lockHandle);
resetErrExceptionMapping ();
@ -40,6 +86,15 @@ function acquireLock ($lockFile, $csId)
return array ($lockHandle, $lock, $userAbort);
}
/**
* Release a lock previously acquired by acquireLock.
*
* Sideeffects:
* Sets ignore_user_abort to the value before acquireLock succeds.
*
* Arguments:
* $lock <array[3]>: The array returned by a successfull acquireLock call.
*/
function releaseLock ($lock)
{
setErrExceptionMapping ();

6
pvtest.php

@ -7,8 +7,12 @@ require_once LIBDIR . 'mutualExclusion.php';
//session_start ();
$lock = acquireLock ('lock/lock', '1');
$handle = fopen ('lock/lock1.lck', 'r');
print fgets ($handle);
fclose ($handle);
echo "Lock bekommen\n";
sleep (2);
sleep (1);
releaseLock ($lock);

Loading…
Cancel
Save