PHP Accelerated Download Method?

It is good practice to download your PHP application. I found two ways to load my PHP application. Need some suggestions that are the best way.

First of all.
Define a constant for folder structures

$controllerPath = 'controller';
define('CONTROLLER', str_replace('\\', '/', realpath($controllerPath)).'/');

//usage
require_once CONTROLLER . 'somecontroller.php';

Second
Using ini_set, set the inclusion path to the application root

$rootPath = $_SERVER['DOCUMENT_ROOT'];
$includePath = ini_get('include_path');
ini_set('include_path', '.'.PATH_SEPARATOR.$rootPath.PATH_SEPARATOR.$includePath);

//usage
require_once 'controller/somecontroller.php';

Please tell me the best way.

In the case of a high load application, which would be the best method

+3
source share
5 answers

ini_set, -above- . . ,

require 'coolapp/class/Model.php'
require 'coolapp/display/Router.php'
require 'spinoff/display/JsView.php'
// etc

java com.whatever.app.more , python .

Re:

, , , , . , . - APC, include . - , , javascript ( , APC , ). APC , ~ 50% .

+4

, PHP .

, , , .

+3

, :

  • /include ( , ) , ..
  • , /include mod_rewrite;
  • , , , setup.php, ini, ..
  • Thhat ;
  • .

.htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /include/
RewriteRule ^include/ - [R=404,L]

. . , 404, , 403 (Forbidden). . , " " " ", - . , /include, , .

, , :

require 'Class.php';

__autoload(), .

+1

:

if (!defined('APPLICATION_PATH')) {
    define('APPLICATION_PATH', realpath(getcwd() . '/../application'));
}

/**
 * Add the APPLICATION_PATH and the library dir to the include_path
 */
set_include_path(get_include_path() . PATH_SEPARATOR . APPLICATION_PATH . PATH_SEPARATOR . realpath(APPLICATION_PATH . '/../library'));

/**
 * Load the file loader to setup the class autoloader
 */
include_once 'Loader.php';
if (!class_exists('Loader')) {
    die('Could not load class loader.');
}

spl_autoload_register('Loader::autoload');

. include_path: , , , , . , .

.. /application/, /library/. . , , . ( ), !

Update

, , include_path (, Windows dev , : SQL Server, Ruby ..) , , .

, , - include_path script php.ini.

, . , . , .

, , ? , ( ), . , . , . , , require s.

+1

- PHP- .

0
source

Source: https://habr.com/ru/post/1702555/


All Articles