PHP sessions default timeout

,

Q: would a user eventually be “logged out” after some time of inactivity?
A: It depends on the server configuration or the relevant directives (session.gc_maxlifetime) in php.ini. Typically the default is 24 minutes (1440 seconds), but your webhost may have altered the default to something else.

http://stackoverflow.com/questions/9904105/php-sessions-default-timeout

CakePHP – session timeout: http://stackoverflow.com/questions/20348038/cakephp-session-timeout

Preventing Memory Leaks in PHP

Image resizing need memory. I use this script to prevent memory leak.

I use Intervention Image library for resizing I often get ‘Allowed memory size of …. bytes exhausted (tried to allocate … bytes)’ message.

////////////////////////////////////////////////////
//get memory_limit info from php.ini
$memoryAvailable = filter_var(ini_get(“memory_limit”), FILTER_SANITIZE_NUMBER_INT) * 1048576;

//getting the image width and height
$imageInfo = getimagesize($destinationPath . ‘/’ . $filename);

//This is quite rough and includes a fudge factor, 2.5, which you may want to experiment with.
$requiredMemory = ( $imageInfo[0] * $imageInfo[1] * ($imageInfo[‘bits’] / 8) * $imageInfo[‘channels’] * 2.5 );

//check memory usage
if (memory_get_usage() + $requiredMemory < $memoryAvailable) {

//we have enough memory to resize the image.
}
////////////////////////////////////////////////////

Free PHP obfuscator, Encoding PHP

PHP: Code obfuscation in 10 steps: https://www.blubgoo.com/php-code-obfuscation-in-10-steps/

PhpMinify: http://www.binpress.com/app/phpminify/632

********************
Encoding & Decoding PHP Code: https://perishablepress.com/encoding-decoding-php/

Example: https://perishablepress.com/tools/decoding/

PHP Classes: http://www.phpclasses.org/package/4926-PHP-Obfuscate-PHP-as-base64-encoded-strings.html

GitHub: PHP Obfuscator

Ncryptd, open-source: http://ncryptd.com/

PHP Obfuscator

https://github.com/naneau/php-obfuscator

This is an “obfuscator” for PSR/OOp PHP code. Different from other obfuscators, which often use a (reversible) eval() based obfuscation, this tool actually parses PHP, and obfuscates variable names, methods, etc. This means is can not be reversed by tools such as UnPHP. This library was written out of the need to obfuscate the source for a private library which for various reasons could not be shared without steps to protect the source from prying eyes. It is not technically feasible to “encrypt” PHP source code, while retaining the option to run it on a standard PHP runtime.

install: git clone https://github.com/naneau/php-obfuscator , composer install

Run: path//php-obfuscator$ ./bin/obfuscate obfuscate input output

input, output – directories in the php-obfuscator folder.

 

Design Patterns

Design Patterns
https://refactoring.guru/design-patterns/abstract-factory

PHP Design Patterns

This is a collection of known design patterns and some sample code how to implement them in PHP. Every pattern has a small list of examples (most of them from Zend Framework, Symfony2 or Doctrine2 as I’m most familiar with this software).

https://github.com/domnikl/DesignPatternsPHP

Egy nagyon hasznos, példákkal teletűzdelt összefoglaló a PHP-ban használatos (divatos) programozási mintákról .

Creational

AbstractFactory
Builder
FactoryMethod
Multiton (is considered an anti-pattern! )
Pool
Prototype
SimpleFactory
Singleton  (is considered an anti-pattern! )
StaticFactory

Structural

Adapter
Bridge
Composite
DataMapper
Decorator
DependencyInjection
Facade
FluentInterface
Proxy
Registry

Behavioral

ChainOfResponsibilities
Command
Iterator
Mediator
Memento
NullObject
Observer
Specification
State
Strategy
TemplateMethod
Visitor

More

Delegation
ServiceLocator
Repository

PHPExcel

A pure PHP library for reading and writing spreadsheet file.  https://github.com/PHPOffice/PHPExcel

Home page:  http://phpexcel.codeplex.com/wikipage?title=Examples

Use 01simple-download-xls.php if you want output to a client’s web browser (Excel5)

If you gotn this error: “exception ‘PHPExcel_Calculation_Exception’ with message”.
Add this
$objWriter->setPreCalculateFormulas(false);
row before save:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//$objWriter->setPreCalculateFormulas(false);
$objWriter->save('php://output');

info from here: https://phpexcel.codeplex.com/discussions/237881

Set bold the row, set width:

$objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getFont()->setBold(true);

$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);

*************************

Hide notice: “Notice: Undefined property: PHPExcel_Calculation::$_savedPrecision”

 

Replace this function in calculation.php line 1739

https://phpexcel.codeplex.com/workitem/20797

public function __destruct() {
        if ($this->_savedPrecision != ini_get('precision')) {
        ini_set('precision',$this->_savedPrecision);
    }
 }

for:

//checking if the property exists with isset

public function __destruct() {
    if(isset($this->_savedPrecision)){
    if ($this->_savedPrecision != ini_get('precision')) {
        ini_set('precision',$this->_savedPrecision);
    }
    }
 }

Installing PHPDocumentor 1 and adding to NetBeans IDE

PHPDocumentor 1 , this only works with PHP 5.2 project

C:\Windows\System32>pear install –alldeps PhpDocumentor
WARNING: “pear/PhpDocumentor” is deprecated in favor of “channel://pear.phpdoc.org/phpdocumentor”
WARNING: “pear/XML_Parser” is deprecated in favor of “pear/XML_Parser2”
downloading PhpDocumentor-1.4.4.tgz …
Starting to download PhpDocumentor-1.4.4.tgz (1,534,088 bytes)
………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………….done: 1,534,088 bytes
downloading XML_Beautifier-1.2.2.tgz …
Starting to download XML_Beautifier-1.2.2.tgz (14,587 bytes)
…done: 14,587 bytes
downloading XML_Parser-1.3.4.tgz …
Starting to download XML_Parser-1.3.4.tgz (16,040 bytes)
…done: 16,040 bytes
install ok: channel://pear.php.net/PhpDocumentor-1.4.4
install ok: channel://pear.php.net/XML_Parser-1.3.4
install ok: channel://pear.php.net/XML_Beautifier-1.2.2

C:\Windows\System32>

//////////////////

Setting in NetBeans IDE

https://www.youtube.com/watch?v=RTZXp4EU3wk

Installing PEAR on Windows

E:\>cd E:\server\UniServerZ_2014\core\php54

E:\server\UniServerZ_2014\core\php54>php go-pear.phar

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type ‘all’ to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix)                   : E:\server\UniServerZ_2014\core\php54
2. Temporary directory for processing            : E:\server\UniServerZ_2014\core\php54\tmp
3. Temporary directory for downloads             : E:\server\UniServerZ_2014\core\php54\tmp
4. Binaries directory                            : E:\server\UniServerZ_2014\core\php54
5. PHP code directory ($php_dir)                 : E:\server\UniServerZ_2014\core\php54\pear
6. Documentation directory                       : E:\server\UniServerZ_2014\core\php54\docs
7. Data directory                                : E:\server\UniServerZ_2014\core\php54\data
8. User-modifiable configuration files directory : E:\server\UniServerZ_2014\core\php54\cfg
9. Public Web Files directory                    : E:\server\UniServerZ_2014\core\php54\www
10. Tests directory                               : E:\server\UniServerZ_2014\core\php54\tests
11. Name of configuration file                    : C:\Windows\pear.ini
12. Path to CLI php.exe                           : E:\server\UniServerZ_2014\core\php54

1-12, ‘all’ or Enter to continue:
Beginning install…
Configuration written to C:\Windows\pear.ini…
Initialized registry…
Preparing to install…
installing phar://E:/server/UniServerZ_2014/core/php54/go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.12.tar…
installing phar://E:/server/UniServerZ_2014/core/php54/go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.1.tar…
installing phar://E:/server/UniServerZ_2014/core/php54/go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.5.tar…
installing phar://E:/server/UniServerZ_2014/core/php54/go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar…
installing phar://E:/server/UniServerZ_2014/core/php54/go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.3.tar…
install ok: channel://pear.php.net/Archive_Tar-1.3.12
install ok: channel://pear.php.net/Console_Getopt-1.3.1
install ok: channel://pear.php.net/Structures_Graph-1.0.4
install ok: channel://pear.php.net/XML_Util-1.2.3
install ok: channel://pear.php.net/PEAR-1.9.5
PEAR: Optional feature webinstaller available (PEAR’s web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)
PEAR: To install optional features use “pear install pear/PEAR#featurename”

******************************************************************************
WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<E:\server\UniServerZ_2014\core\php54\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.

Would you like to alter php.ini <E:\server\UniServerZ_2014\core\php54\php-cli.ini>? [Y/n] :

php.ini <E:\server\UniServerZ_2014\core\php54\php-cli.ini> include_path updated.

Current include path           : .;C:\php\pear
Configured directory           : E:\server\UniServerZ_2014\core\php54\pear
Currently used php.ini (guess) : E:\server\UniServerZ_2014\core\php54\php-cli.ini
Press Enter to continue:

** WARNING! Old version found at E:\server\UniServerZ_2014\core\php54, please remove it or be sure to use the new e:\server\uniserverz_2014\core\php54\pear.bat command

The ‘pear’ command is now at your service at e:\server\uniserverz_2014\core\php54\pear.bat

* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under E:\server\UniServerZ_2014\core\php54PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

E:\server\UniServerZ_2014\core\php54>

////////////////////

Finally you have to add that installation path to your PATH environment. Either do this manually (Start > Control Panel > System > Environment) or run (double-click) the newly generated PEAR_ENV.reg that’s now found in the PHP source directory.