check-batch-processing
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "check-batch-processing" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-b8065f2c971e9d4cd914491b4d50f859e3560e23c7669c9a5e23f513968ce1a0. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Analyze batch-processing issues in PHP code, detecting single-item operations where batching is possible, missing bulk inserts, per-iteration API calls inside loops, and high transaction overhead.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.
- Inputs and outputs
- ```markdown
- Testing
- Not tested
Browse files
Frontmatter
name: check-batch-processing
description: Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.Batch Processing Analysis
Analyze PHP code for batch processing opportunities.
Detection Patterns
1. Single-Item vs Bulk Operations
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
# 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
### 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:
// Batch operation
Improvement: For 1000 items:
- Network round trips: 1000 → 1
- Execution time: ~10s → ~100ms
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Areas to improve
-
缺少 When to Use 章节 Reported severity: Minor
文档未明确说明适用场景和使用时机
Recommendation: 建议添加 When to Use 章节,说明何时使用此 Skill 进行分析
Highlights
- 提供 PHP 代码批处理优化分析,解决开发者性能痛点
- 覆盖数据库、API、缓存、文件操作等多个批处理场景
Highlights
- description 明确描述功能边界,触发词完整
- 提供多种 grep 模式便于实际使用
Areas to improve
-
Document is too long Reported severity: Minor
文档约 600 行,超出推荐长度
Recommendation: 建议将部分内容拆分为独立文件或提供摘要版本
Highlights
- 结构清晰,包含检测模式、代码示例、优化建议
- frontmatter 完整,输出格式规范
Areas to improve
-
缺少集成说明 Reported severity: Minor
未说明如何集成到实际开发工作流
Recommendation: 建议提供自动化检测脚本或 CI/CD 集成示例
Highlights
- 提供具体代码示例和 grep 模式
- 覆盖事务回滚、内存管理等异常场景
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.