PHP and money calculations

Updated: 10th January 2024
Tags: php

Please, use integer as cents, don't do my mistake, if you are using PHP.

I was shocked when discovered that php is using float and doesn't have decimal. I have a lot of code already done, so I used bcmath to get around, but if I had known this earlier, I would have used integers.

php get link from atom feed

Updated: 26th May 2023
Tags: php

How to read rss or atom with php

Updated: 26th May 2023
Tags: php

How to post to facebook page using api with plain php

Updated: 26th April 2023
Tags: php facebook

crop center and resize image using cwebp respecting aspect ratio (php)

Updated: 30th March 2023
Tags: php cwebp

Convert php array to javascript array

Updated: 28th March 2023
Tags: php javascript

[Solved] file_put_contents(/bootstrap/cache/packages.php): failed to open stream: Permission denied

Updated: 17th February 2023
Tags: laravel php ubuntu

php echo (convert) date to RFC 3339

Updated: 3th February 2023
Tags: php
echo date(DATE_RFC3339);
//convert from other format
echo date(DATE_RFC3339, strtotime('2023-01-01 05:55:55'));

[Solved] PHP Fatal error: Allowed memory size bytes exhausted (tried to allocate 67108872 bytes) in Composer/DependencyResolver/RuleSet.php on line 83

Updated: 14th October 2022
Tags: php composer

Remove index.php from url nginx laravel

Updated: 8th June 2022
Tags: nginx php

My programming tips after 10 years of programming

Updated: 28th April 2022
Tags: php mysql

Redis vs Memcache for PHP

Updated: 24th March 2022
Tags: redis memcached php

Memcache. It allows you to store both strings and php arrays and have fun. If it is not enough, try redis.

PHP how to make work curl with CURLOPT_SSL_VERIFYHOST or fix php curl SSL certificate

Updated: 23th March 2022
Tags: php curl

Don't rely on isset to check if it is isset!

Updated: 15th June 2021
Tags: php

Php isset will tell false if variable is null.

//false
isset($a[1]);

$a[1] = null;
//false
isset($a[1]);

That's why you should use array_key_exists if you need to check if it is set or not.

//false
array_key_exists($a[1]);

$a[1] = null;
//true
array_key_exists($a[1]);

Laravel clear queue job code cache

Updated: 12th April 2021
Tags: php laravel

Laravel queue job is caching your job php code, so after updating job code you need to:

php artisan queue:restart

PHP server cmd command

Updated: 6th February 2020
Tags: php

PHP server in current directory

php -S localhost:8000

PHP server in public directory

php -S localhost:8000 -t public

PHP Simple PDO class

Updated: 23th December 2019
Tags: php mysql sql

Laravel select random row from table

Updated: 22th December 2019
Tags: php laravel sql

Get randow row from table in laravel 5.3+

$randomRow = DB::table('table')
            ->inRandomOrder()
            ->first();

Get randow id from table in laravel 5.3+

$randomId = DB::table('table')
            ->inRandomOrder()
            ->value('id');

Increase laravel performance

Updated: 20th December 2019
Tags: php laravel

Update laravel/installer global

Updated: 20th December 2019
Tags: php composer laravel