承接 inwebo/save-page-now-2 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

inwebo/save-page-now-2

Composer 安装命令:

composer require inwebo/save-page-now-2

包简介

Capture a web page as it appears now for use as a trusted citation in the future.

README 文档

README

PHP 8.1+ client library for the Save Page Now 2 (SPN2) API provided by the Internet Archive.

Official Documentation

Installation

composer require inwebo/save-page-now-2

Obtain your S3 API keys at https://archive.org/account/s3.php.

Quick Start

use Inwebo\SavePageNow2\Auth\S3Credentials;
use Inwebo\SavePageNow2\Capture\CaptureOptionsBuilder;
use Inwebo\SavePageNow2\Response\JobStatus;
use Inwebo\SavePageNow2\SavePageNow2Client;
use Symfony\Component\HttpClient\HttpClient;

$client = new SavePageNow2Client(
    HttpClient::create(),
    new S3Credentials('my-access-key', 'my-secret'),
);

// 1. Submit a URL
$options = (new CaptureOptionsBuilder())
    ->withSkipFirstArchive()   // Faster
    ->withJsBehaviorTimeout(0) // No JS execution
    ->build();

$job = $client->capture('https://example.com/', $options);
echo "Job started: {$job->jobId}\n";

// 2. Poll until completion
do {
    sleep(5);
    $status = $client->getStatus($job->jobId);
} while ($status->getStatus() === JobStatus::Pending);

// 3. Result
if ($status->getStatus() === JobStatus::Success) {
    echo "✅ Archived: {$status->getWaybackUrl()}\n";
} else {
    echo "❌ Error: {$status->getMessage()} ({$status->getStatusExt()})\n";
}

Architecture

src/
├── Auth/
│   ├── AuthInterface.php          Generic authentication interface
│   ├── S3Credentials.php          Authorization: LOW key:secret (recommended)
│   └── CookieCredentials.php      logged-in-user + logged-in-sig (fallback)
│
├── Capture/
│   ├── CaptureOptions.php         Readonly Value object — all POST parameters
│   └── CaptureOptionsBuilder.php  Immutable fluent builder
│
├── Response/
│   ├── JobStatus.php              Enum: Pending | Success | Error
│   ├── CaptureJobResponse.php     POST /save response {url, job_id}
│   ├── UserStatusResponse.php     GET /save/status/user {available, processing}
│   ├── SystemStatusResponse.php   GET /save/status/system {status}
│   └── Status/
│       ├── StatusResponseInterface.php
│       ├── StatusResponseFactory.php   Dispatches JSON → correct implementation
│       ├── PendingStatusResponse.php
│       ├── SuccessStatusResponse.php   + getWaybackUrl()
│       └── ErrorStatusResponse.php     + getStatusExt(), getMessage()
│
├── Exception/
│   ├── SavePageNowException.php       Base exception
│   ├── ApiException.php               Unexpected / malformed response
│   ├── AuthenticationException.php    HTTP 401 / error:unauthorized
│   ├── UserSessionLimitException.php  error:user-session-limit
│   └── NetworkException.php           Symfony transport error
│
├── SavePageNow2Interface.php      Public client contract
└── SavePageNow2Client.php         Symfony HttpClient implementation

Complete API

capture(string $url, ?CaptureOptions $options = null): CaptureJobResponse

Submits a URL for archiving. Returns a job_id immediately.

getStatus(string $jobId): StatusResponseInterface

Returns a PendingStatusResponse, SuccessStatusResponse, or ErrorStatusResponse.

getStatuses(array $jobIds): array<string, StatusResponseInterface>

Retrieves the status of multiple jobs in a single request.

getOutlinksStatus(string $parentJobId): array<string, StatusResponseInterface>

Retrieves the status of all outlinks for a parent job (requires capture_outlinks=1).

getUserStatus(): UserStatusResponse

Active and available sessions for the authenticated user.

getSystemStatus(): SystemStatusResponse

Overall health of the SPN2 service.

Capture Options

Builder method API Parameter Description
withCaptureAll() capture_all=1 Also captures 4xx/5xx pages
withCaptureOutlinks() capture_outlinks=1 Automatically archives outlinks
withCaptureScreenshot() capture_screenshot=1 Captures a full-page PNG screenshot
withDelayWbAvailability() delay_wb_availability=1 Available in ~12h (reduces server load)
withForceGet() force_get=1 Forces a simple GET (no headless browser)
withSkipFirstArchive() skip_first_archive=1 Skips the "first archive" check (faster)
withIfNotArchivedWithin(string) if_not_archived_within Only archives if older than e.g., "3d 5h"
withOutlinksAvailability() outlinks_availability=1 Returns the last snapshot timestamp for each outlink
withEmailResult() email_result=1 Sends an email report
withJsBehaviorTimeout(int $s) js_behavior_timeout=N JS execution time after loading (0–30s)
withCaptureCookie(string) capture_cookie Additional HTTP cookie for the target
withTargetCredentials(string, string) target_username/password Credentials for the target's auth forms

Error Handling

use Inwebo\SavePageNow2\Exception\AuthenticationException;
use Inwebo\SavePageNow2\Exception\UserSessionLimitException;
use Inwebo\SavePageNow2\Exception\NetworkException;
use Inwebo\SavePageNow2\Exception\ApiException;

try {
    $job = $client->capture('https://example.com/');
} catch (AuthenticationException $e) {
    // Invalid or expired S3 keys
} catch (UserSessionLimitException $e) {
    // 12 simultaneous captures reached (auth) / 6 (anonymous)
} catch (NetworkException $e) {
    // Transport issue (timeout, DNS...)
} catch (ApiException $e) {
    // Unexpected API response
}

Detailed error codes from status_ext (e.g., error:not-found, error:too-many-daily-captures) are available via ErrorStatusResponse::getStatusExt().

Testing

Run tests using the included PHPUnit runner:

composer phpunit
Save Page Now 2 — Test Suite
========================================
..................................................... 53 / 53
OK (53 tests, 97 assertions)

License

MIT

inwebo/save-page-now-2 适用场景与选型建议

inwebo/save-page-now-2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Internet Archive」 「save page now 2」 「spn2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 inwebo/save-page-now-2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 inwebo/save-page-now-2 我们能提供哪些服务?
定制开发 / 二次开发

基于 inwebo/save-page-now-2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 42
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-22