activity store in file or MySQL database using php which is better

Logs using files are more efficient, however logs stored in the database are easier to read, even remotely.

however that connecting and inserting rows into the database is error prone (database server down, password wrong, out-of-resources).

Log to db instead if you need other people needs to read logs in a web interface or if you need the ability to search through logs. As someone else has pointed out also concurrency matters, if you have a lot of users log to db could scale better.

Yes, it’s faster to write to files but it’s far faster for you to find what you need in the logs if they are in a database.

I think storing logs in database is not a good idea. The pros of storing logs to databases over files is that you can analyze your logs much more easily with the power of SQL, the cons, however, is that you have to pay much more time for database maintenance. You’d better to set up a separate database server to store your logs or your might get too much log INSERT which will decrease your database performance to production use; also, it’s not easy to migrate, archive logs in database, compared with files.

Error logging is best limited to files in my opinion, because if there is a problem with the database.

When using filesystem careful with :

  • Confidentiality : Put documents outside of your Apache Document Root. Then a PHP Controller of yours will output documents.
  • Sharded path : do not store thousands of documents in the same directory, make different directories. You can shard with a Hash on the Filename for example. Such as /documents/A/F/B/AFB43677267ABCEF5786692/myfile.pdf.
  • Inode number : You can run out of inodes if you store a lot of small files (might not be your case if storing mostly PDF and office documents).

mod_expires enable apache2

  1. Confirm that modules are enabled and working in Apache. Also when i write sudo a2enmod expires and sudo a2enmod headers I get a “module already enabled” (And I did restart Apache2)
  2. Double confirm that modules are enabled and working in Apache.To double check this I have also tried removing the <ifModule mod_expires.c> and <ifModule mod_headers.c> lines from my .htaccess file (and the end tags ofc.), to confirm that I can still load the page without getting a server. I have also confirmed that my .htaccess file is working, by writing some junk in it, which does kill my website. (i also have working RewriteRule’s in it)

So to summarize

  1. I am pretty sure the modules are installed and running.
  2. The htaccess file is working and being read by the server.
  3. I have inserted the code in the htaccess file as I should.

compress components with gzip php

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xmlin
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

JavaScript array

JavaScript Simple Array

const nouns= ["Aditya", "Amit", "Ajay"];

JavaScript indexed Array

const cars = [];
cars[0]= "Saab";
cars[1]= "Volvo";
cars[2]= "BMW";

where to find php.ini in linux

ssh user@ip
php -i | grep "Loaded Configuration File"
And it will show you something like this Loaded Configuration File => /etc/php.ini.
ALTERNATIVE METHOD
You can make a php file on your website, which run: <?php phpinfo(); ?>, and you can see the php.ini location on the line with: "Loaded Configuration File".

Validate phone number and email in php

Phone number validation using regular expression

$user_phone = $_POST['user_phone'];

if(!preg_match('/^([0-9]+)$/', $user_phone))
{
    $_SESSION['info']="Please enter valid phone number";
    header('location:/register');
}

Phone number validation using is_numeric function

$user_phone = $_POST['user_phone'];
if(!is_numeric($user_phone))
{
    $_SESSION['info']="Please enter valid phone number";
    header('location:/register');
}
if (filter_var($user_email, FILTER_VALIDATE_EMAIL) == false){
    $_SESSION['info']="Please enter valid email";
    header('location:/register');
}
  • is_int or is_integer
  • is_numeric
  • regular expressions
  • ctype_digit
  • filter_var

is_integer()

for this function these values are are not valid: “0010”, “123”

is_numeric()

for this function these values are valid: 1.3, +1234e44 and 0x539

filter_var()

for this function a value as “00123” is not valid

CONSLUSION

it seems that only regex and ctype_digit work always fine.

upgrade php 7.4 to 8 ubuntu

Check Php Version

$ php -v

Enable new php and Disable old php

sudo a2dismod php7.4
sudo a2enmod php8.0
  
sudo service apache2 restart

composer fund

composer fund
Do not run Composer as root/super user! See https://getcomposer.org/root for det ails
Continue as root/super user [yes]? y
Info from https://repo.packagist.org: #StandWithUkraine
The following packages were found in your dependencies which publish funding inf ormation:

brick
math
https://github.com/sponsors/BenMorel
https://tidelift.com/funding/github/packagist/brick/math

doctrine
inflector, instantiator, lexer
https://www.doctrine-project.org/sponsorship.html
https://www.patreon.com/phpdoctrine
inflector
https://tidelift.com/funding/github/packagist/doctrine%2Finflector
instantiator
https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator
lexer
https://tidelift.com/funding/github/packagist/doctrine%2Flexer

dragonmantank
cron-expression
https://github.com/sponsors/dragonmantank

egulias
email-validator
https://github.com/sponsors/egulias

facade
flare-client-php
https://github.com/sponsors/spatie

filp
whoops
https://github.com/sponsors/denis-sokolov

fruitcake
laravel-cors
https://fruitcake.nl
https://github.com/sponsors/barryvdh

graham-campbell
result-type
https://github.com/sponsors/GrahamCampbell
https://tidelift.com/funding/github/packagist/graham-campbell/result-type

guzzlehttp
guzzle, promises, psr7
https://github.com/sponsors/GrahamCampbell
https://github.com/sponsors/Nyholm
guzzle
https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle
promises
https://tidelift.com/funding/github/packagist/guzzlehttp/promises
psr7
https://tidelift.com/funding/github/packagist/guzzlehttp/psr7

lcobucci
jwt
https://github.com/sponsors/lcobucci
https://www.patreon.com/lcobucci

league
commonmark
https://www.colinodell.com/sponsor
https://www.paypal.me/colinpodell/10.00
https://github.com/sponsors/colinodell
https://tidelift.com/funding/github/packagist/league/commonmark
flysystem
https://offset.earth/frankdejonge
flysystem, mime-type-detection
https://github.com/sponsors/frankdejonge
https://tidelift.com/funding/github/packagist/league/flysystem
oauth2-server
https://github.com/sponsors/sephster
uri, uri-interfaces
https://github.com/sponsors/nyamsprod

monolog
monolog
https://github.com/sponsors/Seldaek
https://tidelift.com/funding/github/packagist/monolog/monolog

myclabs
deep-copy
https://tidelift.com/funding/github/packagist/myclabs/deep-copy

nesbot
carbon
https://opencollective.com/Carbon
https://tidelift.com/funding/github/packagist/nesbot/carbon

nunomaduro
collision
https://www.paypal.com/paypalme/enunomaduro
https://github.com/sponsors/nunomaduro
https://www.patreon.com/nunomaduro

nyholm
psr7
https://github.com/sponsors/Zegnat
https://github.com/sponsors/nyholm

phar-io
manifest
https://github.com/sponsors/theseer

phpoption
phpoption
https://github.com/sponsors/GrahamCampbell
https://tidelift.com/funding/github/packagist/phpoption/phpoption

phpseclib
phpseclib
https://github.com/sponsors/terrafrost
https://www.patreon.com/phpseclib
https://tidelift.com/funding/github/packagist/phpseclib/phpseclib

phpunit
php-code-coverage, php-file-iterator, php-invoker, php-text-template, php-time r, phpunit
https://github.com/sponsors/sebastianbergmann
phpunit
https://phpunit.de/sponsors.html

ramsey
collection, uuid
https://github.com/sponsors/ramsey
collection
https://tidelift.com/funding/github/packagist/ramsey/collection
uuid
https://tidelift.com/funding/github/packagist/ramsey/uuid

sebastian
cli-parser, code-unit, code-unit-reverse-lookup, comparator, complexity, diff, environment, exporter, global-state, lines-of-code, object-enumerator, object-r eflector, recursion-context, resource-operations, type, version
https://github.com/sponsors/sebastianbergmann

spatie
laravel-permission
https://github.com/sponsors/spatie

swiftmailer
swiftmailer
https://github.com/sponsors/fabpot
https://tidelift.com/funding/github/packagist/swiftmailer/swiftmailer

symfony
console, css-selector, deprecation-contracts, error-handler, event-dispatcher, event-dispatcher-contracts, finder, http-foundation, http-kernel, mime, polyfil l-ctype, polyfill-iconv, polyfill-intl-grapheme, polyfill-intl-idn, polyfill-int l-normalizer, polyfill-mbstring, polyfill-php72, polyfill-php73, polyfill-php80, polyfill-php81, process, psr-http-message-bridge, routing, service-contracts, s tring, translation, translation-contracts, var-dumper
https://symfony.com/sponsor
https://github.com/sponsors/fabpot
https://tidelift.com/funding/github/packagist/symfony/symfony

theseer
tokenizer
https://github.com/sponsors/theseer

vlucas
phpdotenv
https://github.com/sponsors/GrahamCampbell
https://tidelift.com/funding/github/packagist/vlucas/phpdotenv

voku
portable-ascii
https://www.paypal.me/moelleken
https://github.com/sponsors/voku
https://opencollective.com/portable-ascii
https://www.patreon.com/voku
https://tidelift.com/funding/github/packagist/voku/portable-ascii

Please consider following these links and sponsoring the work of package authors !
Thank you!