0

I have the below API. CityData.php is a file with city and zip which has a size of 100kb. With this function the interpreter loads the file from disk to memory on each request. How can I avoid this and share it between requests?

<?php
    require_once 'Config.php';
    class CourseController{
        public function getCourseApi()
        {
            require_once 'CityData.php';
            ......
        }
    }

CityData.php

  130433 => '馆陶县',
  130434 => '魏县',
  130435 => '曲周县',
  130481 => '武安市',
  130500 => '邢台市',
  130502 => '桥东区',
........
LF00
  • 27,015
  • 29
  • 156
  • 295
  • What does the file contain exactly, just data? You should probably either split it up (and use an autoloader...) or move the data to a database. If you need the data in memory you can use a memory table or something like redis. – jeroen Jun 26 '19 at 12:41
  • since it's basically data, i suggest you put it on a database – rai Jun 26 '19 at 12:42
  • This has been extensivley discussed. You can store the file in the database or keep it in memory for instance. This question has been answered very well in the possible duplicate I suggested. – Blackbam Jun 26 '19 at 12:47
  • 2
    Possible duplicate of [Store PHP variables in memory between script executions](https://stackoverflow.com/questions/10868696/store-php-variables-in-memory-between-script-executions) – Blackbam Jun 26 '19 at 12:47

1 Answers1

1

Mem Cash is a good solution you can load data for one time then it will available in the RAM for how long you want.

Odai Nasser
  • 112
  • 10