check-batch-processing

Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.

59 stars

Best use case

check-batch-processing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.

Teams using check-batch-processing should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/check-batch-processing/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/check-batch-processing/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/check-batch-processing/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How check-batch-processing Compares

Feature / Agentcheck-batch-processingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Batch Processing Analysis

Analyze PHP code for batch processing opportunities.

## Detection Patterns

### 1. Single-Item vs Bulk Operations

```php
// SLOW: Individual inserts
foreach ($users as $user) {
    $pdo->query("INSERT INTO users (name, email) VALUES ('$name', '$email')");
}

// FAST: Bulk insert
$values = [];
$params = [];
foreach ($users as $i => $user) {
    $values[] = "(:name{$i}, :email{$i})";
    $params["name{$i}"] = $user['name'];
    $params["email{$i}"] = $user['email'];
}
$sql = "INSERT INTO users (name, email) VALUES " . implode(', ', $values);
$pdo->prepare($sql)->execute($params);
```

### 2. Individual Database Operations

```php
// SLOW: Save each entity separately
foreach ($entities as $entity) {
    $this->em->persist($entity);
    $this->em->flush();
}

// FAST: Batch persist and single flush
foreach ($entities as $entity) {
    $this->em->persist($entity);
}
$this->em->flush();

// FAST: With memory management for large batches
$batchSize = 100;
foreach ($entities as $i => $entity) {
    $this->em->persist($entity);
    if ($i % $batchSize === 0) {
        $this->em->flush();
        $this->em->clear();
    }
}
$this->em->flush();
```

### 3. Individual API Calls in Loops

```php
// SLOW: HTTP call per item
foreach ($products as $product) {
    $price = $this->pricingApi->getPrice($product->getSku());
    $product->setPrice($price);
}

// FAST: Batch API call
$skus = array_map(fn($p) => $p->getSku(), $products);
$prices = $this->pricingApi->getPrices($skus);
foreach ($products as $product) {
    $product->setPrice($prices[$product->getSku()]);
}

// SLOW: Individual notifications
foreach ($users as $user) {
    $this->emailService->send($user->getEmail(), $message);
}

// FAST: Batch send
$emails = array_map(fn($u) => $u->getEmail(), $users);
$this->emailService->sendBatch($emails, $message);
```

### 4. Transaction Overhead

```php
// SLOW: Transaction per operation
foreach ($transfers as $transfer) {
    $this->connection->beginTransaction();
    try {
        $this->processTransfer($transfer);
        $this->connection->commit();
    } catch (Exception $e) {
        $this->connection->rollBack();
    }
}

// FAST: Single transaction (if appropriate)
$this->connection->beginTransaction();
try {
    foreach ($transfers as $transfer) {
        $this->processTransfer($transfer);
    }
    $this->connection->commit();
} catch (Exception $e) {
    $this->connection->rollBack();
}

// BALANCED: Chunked transactions
$chunks = array_chunk($transfers, 100);
foreach ($chunks as $chunk) {
    $this->connection->beginTransaction();
    try {
        foreach ($chunk as $transfer) {
            $this->processTransfer($transfer);
        }
        $this->connection->commit();
    } catch (Exception $e) {
        $this->connection->rollBack();
    }
}
```

### 5. Individual File Operations

```php
// SLOW: Separate file writes
foreach ($lines as $line) {
    file_put_contents($path, $line . "\n", FILE_APPEND);
}

// FAST: Batch write
$content = implode("\n", $lines);
file_put_contents($path, $content);

// FAST: Stream for large data
$handle = fopen($path, 'w');
foreach ($lines as $line) {
    fwrite($handle, $line . "\n");
}
fclose($handle);
```

### 6. Individual Cache Operations

```php
// SLOW: Individual cache calls
foreach ($items as $item) {
    $this->cache->set('item:' . $item->getId(), $item);
}

// FAST: Multi-set
$cacheItems = [];
foreach ($items as $item) {
    $cacheItems['item:' . $item->getId()] = $item;
}
$this->cache->setMultiple($cacheItems);

// SLOW: Individual gets
$results = [];
foreach ($ids as $id) {
    $results[$id] = $this->cache->get('item:' . $id);
}

// FAST: Multi-get
$keys = array_map(fn($id) => 'item:' . $id, $ids);
$results = $this->cache->getMultiple($keys);
```

### 7. Queue Message Publishing

```php
// SLOW: Individual publish
foreach ($events as $event) {
    $this->queue->publish($event);
}

// FAST: Batch publish
$this->queue->publishBatch($events);

// With RabbitMQ
$channel->batch_basic_publish();
foreach ($messages as $message) {
    $channel->batch_basic_publish($message, $exchange, $routingKey);
}
$channel->publish_batch();
```

### 8. Update vs Bulk Update

```php
// SLOW: Individual updates
foreach ($users as $user) {
    $user->setStatus('inactive');
    $this->em->flush();
}

// FAST: Bulk DQL update
$this->em->createQuery(
    'UPDATE User u SET u.status = :status WHERE u.id IN (:ids)'
)->setParameters([
    'status' => 'inactive',
    'ids' => array_map(fn($u) => $u->getId(), $users)
])->execute();
```

## Grep Patterns

```bash
# flush() in loop
Grep: "foreach.*->flush\(\)" --glob "**/*.php"

# API/HTTP calls in loop
Grep: "foreach.*->(request|get|post|send)\(" --glob "**/*.php"

# file_put_contents with APPEND in loop
Grep: "foreach.*file_put_contents.*FILE_APPEND" --glob "**/*.php"

# cache->set in loop
Grep: "foreach.*->set\(" --glob "**/*.php"

# Individual INSERT
Grep: "foreach.*INSERT INTO" --glob "**/*.php"
```

## Batch Size Guidelines

| Operation | Recommended Batch Size |
|-----------|------------------------|
| Database inserts | 100-1000 |
| Doctrine flush | 50-100 |
| API calls | Depends on API limits |
| Cache operations | 100-500 |
| File writes | Buffer in memory, single write |
| Queue publish | 100-500 |

## Severity Classification

| Pattern | Severity |
|---------|----------|
| Individual DB operations in loop | 🔴 Critical |
| HTTP calls in loop | 🔴 Critical |
| flush() per entity | 🟠 Major |
| Individual cache operations | 🟠 Major |
| Individual file appends | 🟡 Minor |

## Output Format

```markdown
### Batch Processing Issue: [Description]

**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Individual DB|API Loop|Transaction Overhead|...]

**Issue:**
[Description of the batch processing problem]

**Current:** N operations in loop
**Optimal:** 1 batch operation

**Code:**
```php
// Individual operations
```

**Optimization:**
```php
// Batch operation
```

**Improvement:**
For 1000 items:
- Network round trips: 1000 → 1
- Execution time: ~10s → ~100ms
```

Related Skills

create-health-check

59
from dykyi-roman/awesome-claude-code

Generates Health Check pattern for PHP 8.4. Creates application-level health endpoints with component checkers (Database, Redis, RabbitMQ), status aggregation, and RFC-compliant JSON response. Includes unit tests.

create-docker-healthcheck

59
from dykyi-roman/awesome-claude-code

Generates Docker health check scripts for PHP services. Creates PHP-FPM, Nginx, and custom endpoint health checks.

check-xxe

59
from dykyi-roman/awesome-claude-code

Analyzes PHP code for XML External Entity vulnerabilities. Detects unsafe XML parsers, missing entity protection, LIBXML flags issues, XSLT attacks.

check-version-consistency

59
from dykyi-roman/awesome-claude-code

Audits version consistency across project files. Checks composer.json, README, CHANGELOG, docs, and configuration files for version number synchronization.

check-type-juggling

59
from dykyi-roman/awesome-claude-code

Detects PHP type juggling vulnerabilities. Identifies loose comparison with user input, in_array without strict mode, switch statement type coercion, and hash comparison bypasses.

check-timeout-strategy

59
from dykyi-roman/awesome-claude-code

Audits timeout configuration across HTTP clients, database connections, queue consumers, cache operations, and external service calls. Detects missing or misconfigured timeouts.

check-test-quality

59
from dykyi-roman/awesome-claude-code

Analyzes PHP test code quality. Checks test structure, assertion quality, test isolation, naming conventions, AAA pattern adherence.

check-ssrf

59
from dykyi-roman/awesome-claude-code

Analyzes PHP code for SSRF vulnerabilities. Detects unvalidated URLs, internal network access, DNS rebinding, cloud metadata access, URL parsing bypass attempts.

check-sql-injection

59
from dykyi-roman/awesome-claude-code

Analyzes PHP code for SQL injection vulnerabilities. Detects query concatenation, ORM misuse, raw queries, dynamic identifiers, prepared statement bypasses.

check-serialization

59
from dykyi-roman/awesome-claude-code

Analyzes PHP code for serialization overhead. Detects inefficient JSON encoding, large object hydration, missing JsonSerializable, circular reference issues.

check-sensitive-data

59
from dykyi-roman/awesome-claude-code

Analyzes PHP code for sensitive data exposure. Detects plaintext secrets, exposed credentials, PII in logs, insecure storage, hardcoded keys.

check-secure-headers

59
from dykyi-roman/awesome-claude-code

Audits HTTP security headers configuration. Checks CSP, X-Frame-Options, HSTS, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, and cache control headers.