Skip to main content
Base Platform  /  Code Snippet Archive

Code Snippet & Reference Library

Battle-tested, copy-pasteable snippets across PHP, Python, JavaScript, VB.NET, SQL and Bash — compiled from real SaaS engineering sessions.

469
Snippets Indexed
2
PHP
0
JavaScript
7
Python
✕ Clear

Showing 3 snippets · General

Clear filters
SNP-2025-0023 General 2024-12-22

How to Automatically Update CyberPanel Disk Usage Every Minute: A Step-by-Step Guide

THE PROBLEM
  1. Open the cron job editor:bashCopy codecrontab -e
  2. Add the following line to run the disk usage update every minute:bashCopy code* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py CalculateAndUpdateDiskUsage > /dev/null 2>&1
  3. Add this second line to check disk usage every minute:bashCopy code* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py checkDiskUsage > /dev/null 2>&1
  4. Save and exit:
    • Nano: Ctrl + O, then Ctrl + X
    • Vim: :wq

Make sure the cron service is active and running:

bashCopy codesystemctl restart crond

Check cron service status:

bashCopy codesystemctl status crond

List all active cron jobs to verify:

bashCopy codecrontab -l

You should see:

javascriptCopy code* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py CalculateAndUpdateDiskUsage > /dev/null 2>&1
* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py checkDiskUsage > /dev/null 2>&1

After a few minutes, check the CyberPanel logs:

bashCopy codetail -f /usr/local/CyberCP/debug.log

Look for any errors related to disk usage.


  • Running the script every minute can slightly increase CPU and disk usage. Monitor server performance using:bashCopy codetop
  • If you notice server slowdowns, consider reducing the frequency to every 5 minutes:bashCopy code*/5 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py

If systemctl restart crond is not working, it could mean that your server is not using crond or the service is named differently. Follow these steps to troubleshoot and resolve the issue:


Run the following command to see if cron is installed:

bashCopy codecrontab -l

If it displays your cron jobs, cron is installed. If not, install it:

  • For CentOS/RHEL:bashCopy codeyum install cronie -y
  • For Debian/Ubuntu:bashCopy codeapt install cron -y

The cron service might be named differently depending on your OS:

  • On CentOS/RHEL:bashCopy codesystemctl status crond
  • On Debian/Ubuntu:bashCopy codesystemctl status cron

If the service is cron instead of crond, restart it:

bashCopy codesystemctl restart cron

If the service is stopped or disabled, enable and start it:

bashCopy codesystemctl enable crond
systemctl start crond

Or, if your system uses cron instead:

bashCopy codesystemctl enable cron
systemctl start cron

Check if the cron service is active:

bashCopy codesystemctl status crond

or

bashCopy codesystemctl status cron

If it shows active (running), your cron service is running fine.


To ensure your cron job is working:

  1. Add a test cron job:bashCopy codecrontab -e
  2. Add the following line:bashCopy code* * * * * echo "Cron is working" >> /tmp/cron-test.log
  3. After 2 minutes, check if the log is created:bashCopy codecat /tmp/cron-test.log

If you see Cron is working, your cron setup is fine.


If restarting the cron service doesn’t work, a server reboot might help:

bashCopy codereboot

After restarting the cron service or server:

  1. Verify the cron jobs:bashCopy codecrontab -l
  2. Check the CyberPanel disk usage cron jobs:bashCopy codetail -f /usr/local/CyberCP/debug.log
  3. Monitor disk usage from the CyberPanel dashboard.
REAL-WORLD USAGE EXAMPLE
  1. Log in to CyberPanel Dashboard.
  2. Navigate to Websites > Manage Website > Disk Usage.
  3. Confirm that the disk usage is updating every minute.

Open Full Snippet Page ↗
SNP-2025-0022 General 2024-12-21

How to Upgrade PHP 7 WordPress Backups for Compatibility with PHP 8.2 Without Errors

THE PROBLEM

Short Answer: Partially, but not perfectly.
While some PHP 7 code will still work on PHP 8.2, many deprecated features, removed functions, and syntax changes will cause errors and warnings in your application.


  • Functions like create_function() have been removed.
  • implode() now requires the correct parameter order.
  • Deprecated functions in PHP 7 are now fully removed in PHP 8.2.

Example:

phpCopy code// PHP 7: Works
$func = create_function('$a', 'return $a * 2;');

// PHP 8: Fatal Error
  • PHP 8 enforces stricter type checks.
  • Type mismatches now throw TypeError exceptions instead of warnings.

Example:

phpCopy codefunction add(int $a, int $b) {
    return $a + $b;
}

echo add('2', '3'); // PHP 7: Works, PHP 8: TypeError
  • Introduced in PHP 8.
  • Older codebases may not use it, causing issues in modern PHP setups.

Example:

phpCopy code$user = $session?->user?->name;
  • If your PHP 7 code uses reserved names as function arguments, it will cause errors.

Example:

phpCopy codefunction example($param) {}
example(param: 'value'); // PHP 7: Error
  • PHP 8 introduced a new syntax for constructor property definitions.
  • Older code won't break but won't benefit from this feature.

  • Ensure WordPress, plugins, and themes are updated to their latest versions.
  • Install: PHP Compatibility Checker plugin.
  • Run scans: Identify incompatible functions and syntax.

Enable error reporting in wp-config.php:

phpCopy codedefine('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Review wp-content/debug.log for deprecated warnings and fatal errors.

  • Replace removed functions like create_function() with alternatives.
  • Fix type errors and incorrect function parameter orders.

Before moving to PHP 8.2:

  • Create a staging environment.
  • Test everything thoroughly.
  • If you can’t resolve errors immediately, downgrade to PHP 7.4 temporarily.
  • Fix issues incrementally while testing in PHP 8.2.

FeaturePHP 7.4PHP 8.0PHP 8.2
create_function✅ Yes❌ No❌ No
Type Enforcement⚠️ Weak✅ Strong✅ Strong
Deprecated Warnings✅ Yes⚠️ More Strict⚠️ Very Strict
Nullsafe Operator❌ No✅ Yes✅ Yes
Named Arguments❌ No✅ Yes✅ Yes

  • Short-Term Fix: Downgrade to PHP 7.4 if you’re in a hurry.
  • Long-Term Plan: Refactor and test your code, plugins, and themes for PHP 8.2 compatibility.

While there isn’t a fully automated tool to guarantee a 100% perfect migration, there are reliable tools and services to help analyze, upgrade, and refactor PHP code for PHP 8.2 compatibility.


  • Website: https://getrector.com/
  • Purpose: Automatically refactors and upgrades PHP codebases.
  • How It Works:
    1. Install via Composer:bashCopy codecomposer require rector/rector --dev
    2. Run upgrade commands:bashCopy codevendor/bin/rector process src --set php82
  • Pros: Open-source, customizable rules for PHP 8.2 upgrades.
  • Best For: Developers with technical knowledge.

  • Website: https://phpstan.org/
  • Purpose: Static code analysis tool to detect compatibility issues.
  • How It Works:
    1. Install via Composer:bashCopy codecomposer require phpstan/phpstan --dev
    2. Run analysis:bashCopy codevendor/bin/phpstan analyse src
  • Pros: Pinpoints specific compatibility issues.
  • Best For: Code analysis and compatibility checks.

  • Website: PHP Compatibility Checker Plugin
  • Purpose: Scans WordPress themes and plugins for PHP 8.2 compatibility.
  • How It Works:
    1. Install the plugin.
    2. Run a compatibility scan.
  • Pros: Easy to use within WordPress Dashboard.
  • Best For: Non-technical users to identify problems.

  • Website: https://codecrafters.io/
  • Purpose: Offers manual code upgrade services to PHP 8.x.
  • How It Works:
    1. Submit your project files.
    2. Get a quote for upgrading to PHP 8.2.
  • Pros: Experienced developers handle the upgrade.
  • Best For: Complex or large projects.

If you want professional help for a PHP upgrade, you can hire a developer:

  • Website: https://www.upwork.com/
  • How It Works:
    • Post a project for "PHP 8.2 Upgrade."
    • Get bids from experienced PHP developers.
  • Website: https://www.fiverr.com/
  • How It Works:
    • Search for "PHP Upgrade Services."
    • Choose a freelancer with good reviews.
  • Website: https://www.toptal.com/
  • How It Works:
    • Get matched with top PHP developers.
    • Ideal for mission-critical applications.

Service/ToolTypeAutomation LevelSkill RequiredBest For
RectorPHPTool✅ High⚠️ ModerateLarge Codebases
PHPStanTool⚠️ Moderate✅ BeginnerCode Compatibility
PHP CheckerPlugin✅ Easy✅ BeginnerWordPress Sites
CodeCraftersManual Service✅ Full Support❌ NoneComplex Projects
FreelancersManual Service✅ Full Support❌ NoneCustom Solutions

  1. Start with RectorPHP – For automated upgrades.
  2. Run PHPStan – Analyze remaining compatibility issues.
  3. Manual Refinement – Hire a professional developer on Upwork or Fiverr if needed.
  4. Test Thoroughly – Use a staging environment before going live.
Open Full Snippet Page ↗
SNP-2025-0002 General 2024-07-06

Installing CyberPanel

THE PROBLEM
sudo apt update && sudo apt upgrade -y
sh <(curl https://cyberpanel.net/install.sh || wget -O - https://cyberpanel.net/install.sh)

CyberPanel Installer v2.1.2

Please enter the number[1-2]: 1

CyberPanel Installer v2.1.2

1. Install CyberPanel with OpenLiteSpeed.

2. Install Cyberpanel with LiteSpeed Enterprise.

3. Exit.

Please enter the number[1-3]: 1

Full Service (default Y): Y

Remote MySQL (default N): N

CyberPanel Version (default Latest Version): "s" Or [Enter]

If Enter then the default Password is “1234567”.

It is recommended that you use “s” to set your own strong password

Memcached  (default Y): Y

Redis (default Y): Y

Watchdog (default Yes): Y

Step 5: Installation

The installation process will proceed automatically. It will take 5-10 minutes, depending on the speed of your server.

Step 6: Finalize Installation

At the end of the installation process, you will be presented with the following screen which contains important information about your configuation. Select and copy it to a safe location for future reference.

Would you like to restart your server now? "y" or Enter

Open Full Snippet Page ↗