PHP Classes

File: Example.php

Recommend this page to a friend!
  Packages of Ramesh Narayan Jangid (Sharma)   Heavy Objects   Example.php   Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Heavy Objects
Store and retrieve objects or arrays in files
Author: By
Last change: Refactoring
Date: 5 months ago
Size: 703 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/AutoloadHeavyObjects.php'; // phpcs:ignore

use HeavyObjects\HeavyObject;

echo
'<pre>';

$stream = fopen(filename: "php://temp", mode: "wr+b");
$heavyObject = new HeavyObject(stream: $stream);

// Load/Write/Update records to file
for ($i = 0; $i < 100; $i++) {
   
$row = [];
    for (
$j = 0; $j < 100; $j++) {
       
$row["Key{$j}"] = rand();
    }
   
$heavyObject->write($row, $keys = "row:{$i}");
}

echo
nl2br(PHP_EOL . memory_get_usage()) . ' Bytes';

$rows = [];

for (
$i = 0; $i < 100; $i++) {
   
$row = [];
    for (
$j = 0; $j < 100; $j++) {
       
$row["Key{$j}"] = rand();
    }
   
$rows[] = $row;
}

echo
nl2br(PHP_EOL . memory_get_usage()) . ' Bytes';