You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Raspberry Pi B+ LEMP服务器PHP更新SQL后空白页问题求助

Troubleshooting the Blank Page Issue on Your Raspberry Pi LEMP Server

Hey Marc, let's break down why you're seeing a blank page after syncing 1900 transactions (way more than your expected 100) on your 512MB Raspberry Pi Model B+. That tiny amount of RAM is almost certainly the main culprit here, but let's walk through step-by-step fixes and checks to get things working again.

1. First, Reveal the Hidden Error (Blank Pages = Hidden PHP Issues)

Blank pages in PHP usually mean errors are being suppressed. Let's uncover them:

  • Temporary error display in your script: Add these lines at the very top of your PHP sync/summary file to force errors to show up:
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    
  • Check server logs (more reliable):
    • View Nginx's error log in real-time:
      sudo tail -f /var/log/nginx/error.log
      
    • View PHP-FPM's log (adjust the version number to match your setup, e.g., php7.4-fpm):
      sudo tail -f /var/log/php7.4-fpm.log
      
    These logs will tell you exactly what's failing—whether it's a memory limit hit, timeout, or database query error.

2. Diagnose Memory Pressure on Your Pi

512MB is barely enough for a basic LEMP stack, let alone processing 1900 transactions. Let's check how your memory is being used:

  • Run this command to see current memory/swap usage:
    free -h
    
    If used memory is near 512MB or swap is being heavily utilized, your system is starved for RAM.
  • Temporary swap boost (for testing only): Pi SD cards don't handle frequent swap writes well, but you can add a temporary swap file to rule out memory issues:
    sudo fallocate -l 512M /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    
    Remember to disable this later if you don't need it with sudo swapoff /swapfile.

3. Tweak PHP Configuration (But Don't Overdo It)

Your PHP settings might be too restrictive for the task:

  • Edit your PHP-FPM config file (e.g., /etc/php/7.4/fpm/php.ini):
    • Raise memory_limit to a reasonable value (don't go over 256MB on a 512MB Pi):
      memory_limit = 256M
      
    • Increase max_execution_time if syncing is timing out:
      max_execution_time = 60
      
  • Restart PHP-FPM to apply changes:
    sudo systemctl restart php7.4-fpm
    

4. Optimize Your Code (The Long-Term Fix)

The real solution is to stop forcing your Pi to handle 1900 transactions at once. Here's how:

  • Batch process transactions: Instead of pulling all 1900 records from the API in one go, fetch and sync them in small chunks (e.g., 100 at a time):
    $offset = 0;
    $batchSize = 100;
    do {
        // Fetch a single batch from the API
        $transactionBatch = get_transactions_from_api($offset, $batchSize);
        if (empty($transactionBatch)) break;
        
        // Sync this batch to your database
        sync_batch_to_db($transactionBatch);
        
        $offset += $batchSize;
    } while (true);
    
  • Let the database do the heavy lifting: For your summary page, don't load all transaction data into PHP to calculate totals. Use SQL aggregate functions like SUM() or COUNT() instead—databases are optimized for this:
    SELECT SUM(amount) AS total_sales, COUNT(*) AS total_transactions FROM transactions;
    
  • Add database indexes: If your summary query is slow, add indexes to columns you're filtering/sorting by (e.g., transaction date):
    CREATE INDEX idx_transaction_date ON transactions(transaction_date);
    

5. Check if the OOM Killer Killed Your Process

If your Pi runs out of memory entirely, the Linux Out-of-Memory (OOM) Killer will terminate processes to save the system. Check if this happened:

dmesg | grep -i oom

If you see a line like Out of memory: Killed process ... (php-fpm), that confirms memory was the issue—batch processing is non-negotiable here.


内容的提问来源于stack exchange,提问作者Marc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:08:52