Testing CreateFreshExpiryDataFile - v1


10/10/04
 

Testing CreateFreshExpiryDataFile - v1

I tried testing it using the code shown below, invoking it from a browser using this URL...

    http://myweb.lsbu.ac.uk/php-cgiwrap/~bushm/expirychecker/test.php4

...and it worked fine.

I subsequently realised that I need to use php4-cgiwrap...

    http://myweb.lsbu.ac.uk/php4-cgiwrap/~bushm/expirychecker/test.php4

...in order to invoke the version 4 PHP interpreter. It didn't work! In other words, although it updated the file date if the file already existed, it couldn't create a file if it didn't already exist. I don't understand this; according to the manual it should. Maybe this is something to do with the fact that PHP4 is still officially "on test" at South Bank; I'm thinking that perhaps it doesn't have full priviledge in terms of creating new files? I'll have to remember this, and maybe re-visit the problem in the future.
 
test.php4

<?php

function CreateExpiryDataFile() {

  // create and open ExpiryData file ("r+" for read/write)
  $ExpiryDataFile = "ExpiryData.xml";
  touch($ExpiryDataFile);
  $ExpiryData_fp = fopen($ExpiryDataFile, "r+");

  // lock ExpiryData file ("2" for exclusive writing lock)
  $lock = flock($ExpiryData_fp, 2);

  // continue when lock is obtained
  if ( $lock) {

    // write today's date
    fwrite($ExpiryData_fp, date("Y-m-d"));
    fwrite($ExpiryData_fp, "\n");

  }

  // unlock and close reminders file ("3" is for unlock)
  $lock = flock($ExpiryData_fp, 3);
  fclose($ExpiryData_fp);

}


/*
MAIN PROGRAM
*/

CreateExpiryDataFile();


?>
 

 
 

<<contents ^top^