目录
关于php中的spl_autoload_register,splautoloadregister
一、自动加载定义
二、spl_autoload_register" >二、spl_autoload_register
目录
1、Single Autoloads
2、Mulitple Autoloads
3、Interfaces
4、一个标准的示例
5、框架中的写法
6、set_include_path 方式
7、PSR-4: Autoloader
首页 后端开发 php教程 关于php中的spl_autoload_register,splautoloadregister_PHP教程

关于php中的spl_autoload_register,splautoloadregister_PHP教程

Jul 12, 2016 am 09:03 AM
spl

关于php中的spl_autoload_register,splautoloadregister

一、自动加载定义

很多开发者写面向对象的应用程序时对每个类的定义建立一个 PHP 源文件。一个很大的烦恼是不得不在每个脚本开头写一个长长的包含文件列表(每个类一个文件)。

在 PHP 5 中,不再需要这样了。可以定义一个 __autoload() 函数,它会在试图使用尚未被定义的类时自动调用。通过调用此函数,脚本引擎在 PHP 出错失败前有了最后一个机会加载所需的类

__autoload 是一个魔术方法, 尝试加载未定义的类,spl_autoload_register - 注册给定的函数作为 __autoload 的实现

<p class="para"><span class="function"><span class="tip"><span class="tip">Tip</span></span></span></p>
<p class="para"><span class="function">spl_autoload_register() 提供了一种更加灵活的方式来实现类的自动加载。因此,不再建议使用 <span class="function">__autoload()函数,在以后的版本中它可能被弃用。</span></span></p>
登录后复制

Note:

在 5.3.0 版之前,__autoload 函数抛出的异常不能被 catch 语句块捕获并会导致一个致命错误。从 5.3.0+ 之后,__autoload 函数抛出的异常可以被 catch 语句块捕获,但需要遵循一个条件。如果抛出的是一个自定义异常,那么必须存在相应的自定义异常类。__autoload 函数可以递归的自动加载自定义异常类。

Note:

自动加载不可用于 PHP 的 CLI 交互模式。

Note:

如果类名比如被用于 call_user_func(),则它可能包含一些危险的字符,比如 ../。 建议您在这样的函数中不要使用用户的输入,起码需要在 __autoload() 时验证下输入

二、spl_autoload_register

目录

classes --+
          + mail.class.php
          + norman.class.php
          + db.class.php
登录后复制

1、Single Autoloads

<?php
    /*** nullify any existing autoloads ***/
    spl_autoload_register(null, false);

    /*** specify extensions that may be loaded ***/
    spl_autoload_extensions('.php, .class.php');

    /*** class Loader ***/
    function classLoader($class)
    {
        $filename = strtolower($class) . '.class.php';
        $file ='classes/' . $filename;
        if (!file_exists($file))
        {
            return false;
        }
        include $file;
    }

    /*** register the loader functions ***/
    spl_autoload_register('classLoader');

    /*** a new instance if norman ***/
    $norman = new norman;

    /*** make norman do something ***/
    $norman->do_something();
?>
登录后复制

2、Mulitple Autoloads

<?php

    /*** nullify any existing autoloads ***/
    spl_autoload_register(null, false);

    /*** specify extensions that may be loaded ***/
    spl_autoload_extensions('.php, .class.php, .lib.php');

    /*** class Loader ***/
    function classLoader($class)
    {
        $filename = strtolower($class) . '.class.php';
        $file ='classes/' . $filename;
        if (!file_exists($file))
        {
            return false;
        }
        include $file;
    }

    function libLoader($class)
    {
        $filename = strtolower($class) . '.lib.php';
        $file ='libs/' . $filename;
        if (!file_exists($file))
        {
            return false;
        }
        include $file;
    }

    /*** register the loader functions ***/
    spl_autoload_register('classLoader');
    spl_autoload_register('libLoader');

    /*** a new instance of norman ***/
    $norman = new norman;

    /*** make norman do some thing ***/
    $norman->do_something();
登录后复制

3、Interfaces

接口文件

<?php
    /*
     * icontroller.class.php
     * interface to ensure all classes have an index method
     *
     */
    interface iController
    {
        public function index();
    }
?>
登录后复制

autoload文件

<?php
    /*** nullify any existing autoloads ***/
    spl_autoload_register(null, false);

    /*** specify extensions that may be loaded ***/
    spl_autoload_extensions('.php, .class.php');

    /*** class Loader ***/
    function classLoader($class)
    {
        $filename = strtolower($class) . '.class.php';
        $file ='classes/' . $filename;
        if (!file_exists($file))
        {
            return false;
        }
        include $file;
    }

    /*** register the loader functions ***/
    spl_autoload_register('classLoader');

    class blog implements iController
    {
        public function index()
        {
            echo 'hello from the index';
        }
    }

    /*** a new blog instance ***/
    $blog = new blog;

    /*** run the index method ***/
    $blog->index();
?>
登录后复制

4、一个标准的示例

spl_autoload_register( 'autoload' );
 
  
  /**
   * autoload
   *
   * @author testdd
   * @param  string $class
   * @param  string $dir
   * @return bool
   */
  function autoload( $class, $dir = null ) {
 
    if ( is_null( $dir ) )
      $dir = '/path/to/project';
 
    foreach ( scandir( $dir ) as $file ) {
 
      // directory?
      if ( is_dir( $dir.$file ) && substr( $file, 0, 1 ) !== '.' )
        autoload( $class, $dir.$file.'/' );
 
      // php file?
      if ( substr( $file, 0, 2 ) !== '._' && preg_match( "/.php$/i" , $file ) ) {
 
        // filename matches class?
        if ( str_replace( '.php', '', $file ) == $class || str_replace( '.class.php', '', $file ) == $class ) {
 
            include $dir . $file;
        }
      }
    }
  }
登录后复制

5、框架中的写法

<?php
/**
 * Autoloader
 * @author Jianxiang Qin <TalkativeDoggy@gmail.com>
 * @license http://opensource.org/licenses/BSD-3-Clause New BSD License
 * @version svn:$Id$
 * @package Lotusphp\Autoloader
 */

/**
 * 自动加载类和函数
 * 
 * 按需加载类,每次只加载用到的类。
 * 
 *     函数库文件不是按需加载!若支持加载函数,则所有定义函数的文件都会加载。
 * 
 * 代码中用到一个类或者函数的时候,不需要使用include/require来包含类库文件或者函数库文件。
 * 
 * 基于Autoloader组件的代码中将不用使用include/require。
 * 
 * Autoloader缓存的是绝对路径,能让Opcode Cache有效缓存文件。
 * 
 *     Autoloader要求类的名字唯一,不在意类文件的路径和文件名。目前不支持命名空间(PHP5.3)
 * 
 * 传统的include/require通常存在以下问题。
 * <ul>
 * <li>目录名和文件名变化引起程序代码变化。</li>
 * <li>Windows和Linux对文件路径的大小写和目录分隔符号的处理不同导致代码在不同平台迁移时出现问题。</li>
 * <li>include_path相对路径的性能低(显著地低)。</li>
 * <li>为了保证不重复包含,使用include_once和require_once导致效率低(不是显著的低)。</li>
 * </ul>
 * @author Jianxiang Qin <TalkativeDoggy@gmail.com> Yi Zhao <zhao5908@gmail.com>
 * @category runtime
 * @package Lotusphp\Autoloader
 * @todo 所有class-file mapping当成一个数据写入storeHandle
 */
class LtAutoloader
{
        /** 
         * @var bool true|false 是否自动加载定义了函数的文件。
         * false 只自动加载定义了class或者interface的文件。
         * true (默认) 自动加载定义了函数的文件。
         */
        public $isLoadFunction = true;
        
        /**
         * @var array 要扫描的文件类型
         * 若该属性设置为array("php","inc","php3"),
         * 则扩展名为"php","inc","php3"的文件会被扫描,
         * 其它扩展名的文件会被忽略
         */
        public $allowFileExtension = array('php', 'inc');
        
        /**
         * @var array 不扫描的目录
         * 若该属性设置为array(".svn", ".setting"),
         * 则所有名为".setting"的目录也会被忽略
         */
        public $skipDirNames = array('.svn', '.git');

        /** @var LtStoreFile 存储句柄默认使用 @link LtStoreFile */
        public $storeHandle;
        
        /** @var array 指定需要自动加载的目录列表 */
        public $autoloadPath;
        
        /** @var bool
     * true 开发模式下  每次都会扫描目录列表
     * false 生产环境下 只扫描一次
     */
        public $devMode = true;
        
        /** @var array 函数名 -> 文件路径  映射 */
        private $functionFileMapping = array();

    /** @var array 类名 -> 文件路径  映射 */
    private $classFileMapping = array();

    /** @var array 定义了函数的文件列表 */
    private $functionFiles = array();

    /** @var LtStoreFile 持久存储句柄,存储文件的get_token_all分析结果/filesize/filehash @link LtStoreFile */
    private $persistentStoreHandle;

    /** @var int store name space id */
    private $storeNameSpaceId;

    /** @var int number of parse error */
    private $parseErrorAmount = 0;

    /** @var int number of library files successfully parsed */
    private $libFileAmount = 0;

        /**
         * 递归扫描指定的目录列表,根据@see LtAutoloader::$isLoadFunction是否加载全部的函数定义文件。
         * 注册自动加载函数,按需加载类文件。
         * @return void
         */
        public function init()
        {
        $this->storeNameSpaceId = sprintf("%u", crc32(serialize($this->autoloadPath)));

        if (true != $this->devMode)
        {
            if ($this->storeHandle instanceof LtStore)
            {
                $this->storeHandle->prefix = 'Lt-Autoloader-' . $this->storeNameSpaceId;
            }
            else
            {
                if (null == $this->storeHandle)
                {
                    $this->storeHandle = new LtStoreFile;
                    $this->storeHandle->prefix = 'Lt-Autoloader-' . $this->storeNameSpaceId;
                    $this->storeHandle->useSerialize = true;
                    $this->storeHandle->init();
                }
                else
                {
                    trigger_error("You passed a value to autoloader::storeHandle, but it is NOT an instance of LtStore");
                }
            }
        }
        else
        {
            $this->storeHandle = new LtStoreMemory;
        }

                // Whether scanning directory
                if ($storedMap = $this->storeHandle->get("map"))
        {
            $this->classFileMapping = $storedMap["classes"];
            $this->functionFiles = $storedMap["functions"];
        }
        else
                {
            $this->setPersistentStoreHandle();
                        $autoloadPath = $this->preparePath($this->autoloadPath);
                        foreach($autoloadPath as $path)
                        {
                                if (is_file($path))
                                {
                                        $this->addFileMap($path);
                                }
                        }
                        $this->scanDirs($autoloadPath);
                        unset($autoloadPath);
                }

                // Whether loading function files
                $this->loadFunctionFiles();
                spl_autoload_register(array($this, "loadClass"));
        }

    protected function setPersistentStoreHandle()
    {
        $this->persistentStoreHandle = new LtStoreFile;
        $this->persistentStoreHandle->prefix = 'Lt-parsed-token-' . $this->storeNameSpaceId;
        $this->persistentStoreHandle->useSerialize = true;
    }

        /**
         * Autoloader扫描项目,若某个php文件中定义了函数,则此文件的绝对路径被缓存,
         * 每次执行LtAutoloader->init()方法时,自动include所有定义了函数的php文件。
     * 因为PHP的Autoload机制是针对Class的.function文件没有办法按需加载
         * @return void
         */
        protected function loadFunctionFiles()
        {
                if ($this->isLoadFunction && count($this->functionFiles))
                {
                        foreach ($this->functionFiles as $functionFile)
                        {
                                include_once($functionFile);
                        }
                }
        }

        /**
         * 被注册的自动加载函数
         * @param string $className
         * @return void 
         */
        protected function loadClass($className)
        {
                if ($filePath = $this->getFilePathByClassName($className))
                {
                        include($filePath);
                }
        }

        /**
         * 将目录分隔符号统一成linux目录分隔符号/
         * @param string $path
         * @return boolean
         */
        protected function convertPath($path)
        {
                $path = str_replace("\\", "/", $path);
                if (!is_readable($path))
                {
                        trigger_error("Directory is not exists/readable: {$path}");
                        return false;
                }
                $path = rtrim(realpath($path), '\\/');
                if (preg_match("/\s/i", $path))
                {
                        trigger_error("Directory contains space/tab/newline is not supported: {$path}");
                        return false;
                }
                return $path;
        }

        /**
         * The string or an Multidimensional array into a one-dimensional array
         * 将字符串和多维数组转换成一维数组
         * @param mixed $paths
         * @return array one-dimensional array
         */
        protected function preparePath($paths)
        {
                $oneDPathArray = array();
                if (!is_array($paths))
                {
                        $paths = array($paths);
                }
                $i = 0;
                while (isset($paths[$i]))
                {
                        if (!is_array($paths[$i]) && $path = $this->convertPath($paths[$i]))
                        {
                                $oneDPathArray[] = $path;
                        }
                        else
                        {
                                foreach($paths[$i] as $v)
                                {
                                        $paths[] = $v;
                                }
                        }
                        $i ++;
                }
        unset($paths);
                return $oneDPathArray;
        }

        /**
         * Using iterative algorithm scanning subdirectories
         * save autoloader filemap
         * 递归扫描目录包含子目录,保存自动加载的文件地图。
         * @param array $dirs one-dimensional
         * @return void
     * @todo in_array换成array_key_exists以提升性能
         */
        protected function scanDirs($dirs)
        {
                $i = 0;
                while (isset($dirs[$i]))
                {
                        $dir = $dirs[$i];
                        $files = scandir($dir);
                        foreach ($files as $file)
                        {
                $currentFile = $dir . DIRECTORY_SEPARATOR . $file;
                if (is_file($currentFile))
                {
                    $this->addFileMap($currentFile);
                }
                else if (is_dir($currentFile))
                {
                    if (in_array($file, array(".", "..")) || in_array($file, $this->skipDirNames))
                    {
                        continue;
                    }
                    else
                    {
                        // if $currentFile is a directory, pass through the next loop.
                        $dirs[] = $currentFile;
                    }
                }
                else
                {
                    trigger_error("$currentFile is not a file or a directory.");
                }
                        } //end foreach
                        $i ++;
                } //end while

        if(0 == $this->parseErrorAmount)
        {
            $this->functionFiles = array_unique(array_values($this->functionFileMapping));
            $map = array("classes" => $this->classFileMapping, "functions" => $this->functionFiles);
            if ($this->storeHandle->get("map"))
            {
                $this->storeHandle->update("map", $map);
            }
            else
            {
                $this->storeHandle->add("map", $map);
            }
        }
        else
        {
            trigger_error($this->parseErrorAmount . " error(s) occoured when scanning and parsing your lib files");
        }
        }

    /**
     * 分析出字符串中的类,接口,函数。 
     * @param string $src
     * @return array
     * @todo 若当前文件包含了直接执行的php语句,或者html,输出警告
     * @todo 若当前文件有语法错误,抛出异常
     */
        protected function parseLibNames($src)
        {
                $libNames = array();
                $tokens = token_get_all($src);
                $level = 0;
                $found = false;
                $name = '';
                foreach ($tokens as $token)
                {
                        if (is_string($token))
                        {
                                if ('{' == $token)
                                {
                                        $level ++;
                                }
                                else if ('}' == $token)
                                {
                                        $level --;
                                }
                        }
                        else
                        {
                                list($id, $text) = $token;
                                if (T_CURLY_OPEN == $id || T_DOLLAR_OPEN_CURLY_BRACES == $id)
                                {
                                        $level ++;
                                }
                                if (0 < $level)
                                {
                                        continue;
                                }
                                switch ($id)
                                {
                                        case T_STRING:
                                                if ($found)
                                                {
                                                        $libNames[strtolower($name)][] = $text;
                                                        $found = false;
                                                }
                                                break;
                                        case T_CLASS:
                                        case T_INTERFACE:
                                        case T_FUNCTION:
                                                $found = true;
                                                $name = $text;
                                                break;
                                }
                        }
                }
                return $libNames;
        }

        /**
         * 保存类名、接口名和对应的文件绝对路径。 
         * @param string $className
         * @param string $file
         * @return boolean
         */
        protected function addClass($className, $file)
        {
                $key = strtolower($className);
                if (isset($this->classFileMapping[$key]))
                {
            $existedClassFile = $this->classFileMapping[$key];
                        trigger_error("duplicate class [$className] found in:\n$existedClassFile\n$file\n, or please clear the cache");
                        return false;
                }
                else
                {
            $this->classFileMapping[$key] = $file;
                        return true;
                }
        }

        /**
         * 保存函数名和对应的文件绝对路径
         * @param string $functionName
         * @param string $file
         * @return boolean
         */
        protected function addFunction($functionName, $file)
        {
                $functionName = strtolower($functionName);
                if (isset($this->functionFileMapping[$functionName]))
                {
                        $existedFunctionFile = $this->functionFileMapping[$functionName];
                        trigger_error("duplicate function [$functionName] found in:\n$existedFunctionFile\n$file\n");
                        return false;
                }
                else
                {
                        $this->functionFileMapping[$functionName] = $file;
                        return true;
                }
        }

        /**
         * 将文件添加到自动加载的FileMap,
         * 添加之前会判断自从上次扫描后有没有修改,若没有修改则无需重复添加,
         * 若修改过,则分析文件内容,根据内容中包含的类、接口,函数添加到FileMap
         * @param string $filePath
         * @return boolean
         */
        protected function addFileMap($filePath)
        {
        if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), $this->allowFileExtension))
        {//init()会调用这个方法, 不要将这个判断移动到scanDir()中
            return false;
        }
        $fileSize = filesize($filePath);
        $fileHash = md5_file($filePath);

        $savedFileInfo = $this->persistentStoreHandle->get($filePath);
                if (!isset($savedFileInfo['file_size']) || $savedFileInfo['file_size'] != $fileSize || $savedFileInfo['file_hash'] != $fileHash)
                {
            if($libNames = $this->parseLibNames(trim(file_get_contents($filePath))))
            {
                $newFileInfo = array('file_size' => $fileSize, 'file_hash' => $fileHash, 'lib_names' => $libNames);
                if (isset($savedFileInfo['file_size']))
                {
                    $this->persistentStoreHandle->update($filePath, $newFileInfo);
                }
                else
                {
                    $this->persistentStoreHandle->add($filePath, $newFileInfo);
                }
            }
                        else
            {
                $this->parseErrorAmount ++;
            }
                }
        else
        {
            $libNames = $savedFileInfo['lib_names'];
        }

        foreach ($libNames as $libType => $libArray)
        {
            $method = "function" == $libType ? "addFunction" : "addClass";
            foreach ($libArray as $libName)
            {
                if (!$this->$method($libName, $filePath))
                {
                    $this->parseErrorAmount ++;
                }
            }
        }
                return true;
        }

    protected function getFilePathByClassName($className)
    {
        $key = strtolower($className);
        if (isset($this->classFileMapping[$key]))
        {
            return $this->classFileMapping[$key];
        }
        else
        {
            return false;
        }
    }
} 
登录后复制

6、set_include_path 方式

set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), './services', './printers')));
spl_autoload_register();
登录后复制

7、PSR-4: Autoloader

http://www.php-fig.org/psr/psr-4/

 

参考文章

http://www.phpro.org/tutorials/SPL-Autoload.html

https://github.com/qinjx/adv_php_book/blob/master/class_autoload.md

http://php.net/manual/zh/language.oop5.autoload.php

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1082309.htmlTechArticle关于php中的spl_autoload_register,splautoloadregister 一、自动加载定义 很多开发者写面向对象的应用程序时对每个类的定义建立一个 PHP 源文件。...
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PHP SPL 数据结构:为你的项目注入速度和灵活性 PHP SPL 数据结构:为你的项目注入速度和灵活性 Feb 19, 2024 pm 11:00 PM

PHPSPL数据结构库概述PHPSPL(标准php库)数据结构库包含一组类和接口,用于存储和操作各种数据结构。这些数据结构包括数组、链表、栈、队列和集合,每个数据结构都提供了一组特定的方法和属性,用于操纵数据。数组在PHP中,数组是存储一系列元素的有序集合。SPL数组类提供了对原生的PHP数组进行加强的功能,包括排序、过滤和映射。以下是使用SPL数组类的一个示例:useSplArrayObject;$array=newArrayObject(["foo","bar","baz"]);$array

PHP SPL 数据结构:一个让你的代码焕然一新的工具包 PHP SPL 数据结构:一个让你的代码焕然一新的工具包 Feb 19, 2024 pm 12:09 PM

PHPSPL数据结构:概述phpSPL数据结构是PHP标准库(SPL)中的一个组件,它提供了一组通用数据结构,包括堆栈、队列、数组和哈希表。这些数据结构经过优化,可高效处理各种数据类型,并提供了一致的接口,简化了应用程序开发。主要数据结构堆栈堆栈是一种遵循后进先出(LIFO)原则的有序集合。在堆栈中,最后一个添加的元素将是第一个被删除的元素。SPL提供了一个SplStack类来表示堆栈。以下示例展示了如何使用SplStack:$stack=newSplStack();$stack->push(1

PHP SPL 数据结构:数据管理的终极武器 PHP SPL 数据结构:数据管理的终极武器 Feb 20, 2024 am 11:30 AM

PHPSPL数据结构库简介PHP标准库(SPL)包含了一组丰富的内置数据类型,称为数据结构。这些结构提供了对复杂数据集合的高效和灵活的管理。使用SPL数据结构可以为您的应用程序带来以下好处:性能优化:SPL数据结构经过专门设计,可在各种情况下提供最佳性能。可维护性提高:这些结构简化了复杂数据类型的处理,从而提高代码的可读性和可维护性。标准化:SPL数据结构符合php编程规范,确保跨应用程序的一致性和互操作性。SPL数据结构类型SPL提供了几种数据结构类型,每种类型都有其独特的特性和用途:栈(St

PHP SPL 数据结构最佳实践:确保代码的健壮性 PHP SPL 数据结构最佳实践:确保代码的健壮性 Feb 19, 2024 pm 03:09 PM

1.选择合适的抽象数据类型(ADT)ADT定义了一组操作和属性,用于抽象地描述数据类型。SPL提供了大量的ADT实现,包括数组、集合、队列和堆栈。选择合适的ADT至关重要,因为它会影响代码的行为和开销。数组(ArrayObject):有序集合,用于存储键值对。集合(SetObject):无序集合,用于存储唯一元素。队列(QueueObject):先进先出(FIFO)数据结构,用于处理消息和事件。堆栈(StackObject):后进先出(LIFO)数据结构,用于递归处理和函数调用。2.使用迭代器进

PHP SPL 数据结构:处理复杂数据的秘密武器 PHP SPL 数据结构:处理复杂数据的秘密武器 Feb 20, 2024 am 11:10 AM

PHPStandardLibrary(SPL)为php提供了一套强大的数据结构,用于高效处理和管理复杂数据。这些数据结构包括数组、集合、有序映射等,它们专门设计为在各种场景下提供优异的性能和灵活性。数组(Array)PHP数组是一个有序集合,它以键值对的形式存储数据。数组广泛用于存储列表、哈希表和关联数组。通过使用内置的array_*函数,可以轻松地创建、操作和遍历数组。$array=["apple","banana","cherry"];array_push($array,"durian");

Java嵌入数据引擎从SQLite到SPL实例分析 Java嵌入数据引擎从SQLite到SPL实例分析 May 05, 2023 pm 09:52 PM

可以在Java应用中嵌入的数据引擎看起来比较丰富,但其实并不容易选择。Redis计算能力很差,只适合简单查询的场景。Spark架构复杂沉重,部署维护很是麻烦。H2\HSQLDB\Derby等内嵌数据库倒是架构简单,但计算能力又不足,连基本的窗口函数都不支持。相比之下,SQLite在架构性和计算能力上取得了较好的平衡,是应用较广的Java嵌入数据引擎。SQLite适应常规基本应用场景SQLite架构简单,其核心虽然是C语言开发的,但封装得比较好,对外呈现为一个小巧的Jar包,能方便地集成在Java

php如何使用PHP的SPL扩展? php如何使用PHP的SPL扩展? Jun 01, 2023 am 08:36 AM

PHP是一种开源的、面向对象的、服务器端的脚本语言,可以用于快速开发动态Web应用程序。PHP的标准库提供了许多常用的函数和类,但有些时候需要处理的数据结构比较复杂,标准库中的功能就不够用了。此时,可以使用PHP的SPL扩展来解决问题。SPL是StandardPHPLibrary的缩写,它是PHP5引入的一个标准库,提供了一系列的接口和类,用于处理各种

PHP SPL 数据结构:释放数据操作的潜力 PHP SPL 数据结构:释放数据操作的潜力 Feb 19, 2024 pm 06:00 PM

探索PHPSPL数据结构的优势phpSPL(标准PHP库)数据结构库是一个宝库,它提供了各种预定义的数据结构,例如数组、队列、堆栈和集合,有助于简化和高效地管理数据。利用这些结构,开发人员可以:提高数据管理效率:SPL数据结构提供了一致的接口和优化算法,简化了数据的存储、检索和操纵。增强代码可读性:使用标准化的结构,代码变得更易于理解和维护,从而提高开发效率。提升性能:SPL数据结构经过优化,可以有效处理大量数据,从而提高应用程序的整体性能。SPL数据结构类型SPL数据结构库涵盖了广泛的数据结构

See all articles