Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dyn Php Laravel Package

dyninc/dyn-php

PHP SDK for Dyn APIs. Manage DNS with Traffic Management (sessions, zones, records, redirects, dynamic DNS) and send email via Message Management. Supports PHP 7.4+, works with Composer, and includes examples and PHPUnit tests.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the package via Composer:

    composer require dyninc/dyn-php
    

    Verify the package loads in config/app.php under providers.

  2. Configuration Publish the config file:

    php artisan vendor:publish --provider="Dyninc\DynPhp\DynPhpServiceProvider" --tag="config"
    

    Update .env with your DynAPI credentials:

    DYN_API_USERNAME=your_username
    DYN_API_PASSWORD=your_password
    DYN_DEBUG=false  # Enable for verbose logging
    
  3. First Use Case: DNS Record Management Fetch a DNS record (e.g., example.com):

    use Dyninc\DynPhp\Client;
    
    $client = new Client();
    $record = $client->getDnsRecord('example.com', 'A');
    dd($record);
    

    New in 0.11.0: Delete DNS records or entire nodes (including child records):

    // Delete a single record
    $client->deleteDnsRecord('example.com', 'A', '192.0.2.1');
    
    // Delete a node and ALL its child records (new capability)
    $client->deleteDnsRecord('example.com', 'A', null, true);
    

Implementation Patterns

Common Workflows

  1. DNS Management

    • Create/Update Records:
      $client->createDnsRecord('example.com', 'A', '192.0.2.1', 3600);
      
    • Delete Records or Nodes:
      // Delete a single record
      $client->deleteDnsRecord('example.com', 'A', '192.0.2.1');
      
      // Delete a node and ALL child records (new in 0.11.0)
      $client->deleteDnsRecord('example.com', 'A', null, true);
      
    • Bulk Updates: Use updateDnsRecords() with an array of record data for batch operations.
  2. Traffic Director (Load Balancing)

    • Configure Pools:
      $client->createPool('web_pool', ['192.0.2.1:80', '192.0.2.2:80']);
      
    • Update Traffic Rules:
      $client->updateTrafficRule('web_pool', 'example.com', 'A', 'roundrobin');
      
  3. Monitoring & Alerts

    • Fetch Alerts:
      $alerts = $client->getAlerts();
      foreach ($alerts as $alert) {
          Log::warning($alert->message);
      }
      

Integration Tips

  • Laravel Artisan Commands Create a custom command for DNS management (e.g., DeleteDnsRecords):

    php artisan make:command DeleteDnsRecords
    

    Use the SDK in the handle() method:

    $client->deleteDnsRecord($domain, $type, $address, $deleteChildren);
    
  • Service Providers Bind the client to the container for dependency injection:

    $this->app->singleton(Client::class, function ($app) {
        return new Client(config('dyn.api_username'), config('dyn.api_password'));
    });
    
  • Event Listeners Trigger actions on Dyn API events (e.g., record deletions):

    event(new DnsRecordDeleted($record));
    
  • Scheduling Cleanup Tasks Schedule a command to delete stale DNS records or nodes:

    // app/Console/Kernel.php
    $schedule->command('delete:stale-dns')->daily();
    

Gotchas and Tips

Pitfalls

  1. Deprecated API

    • The package was last updated in 2018, but the new deleteDnsRecord method now supports node deletion (including child nodes).
    • Workaround: Use curl or Guzzle for unsupported endpoints if needed.
  2. Rate Limiting

    • DynAPI enforces rate limits (~100 requests/minute). Cache responses aggressively:
      $cacheKey = "dyn_records_{$domain}";
      return Cache::remember($cacheKey, now()->addMinutes(5), function () use ($client, $domain) {
          return $client->getDnsRecords($domain);
      });
      
  3. Authentication Failures

    • Ensure .env credentials are correct. Test with:
      try {
          $client->getAccountInfo();
      } catch (\Exception $e) {
          Log::error("Dyn Auth Failed: " . $e->getMessage());
      }
      
  4. Node Deletion Behavior (New in 0.11.0)

    • Critical: Deleting a node with children will recursively delete all child records. Use with extreme caution:
      // Deletes ONLY the specified record (no children)
      $client->deleteDnsRecord('example.com', 'A', '192.0.2.1');
      
      // Deletes the node AND ALL child records (use sparingly)
      $client->deleteDnsRecord('example.com', 'A', null, true);
      
    • Best Practice: Implement a confirmation step or use soft deletion before permanent deletion.
  5. API Versioning

    • The delete node endpoint may behave differently across DynAPI versions. Verify behavior in the DynAPI documentation.

Debugging

  • Enable Verbose Logging Set DYN_DEBUG=true in .env to log raw API responses.

  • Handle Exceptions Wrap SDK calls in try-catch blocks:

    try {
        $client->deleteDnsRecord('example.com', 'A', '192.0.2.1', true);
    } catch (DynException $e) {
        report($e);
        Log::error("Failed to delete DNS node. Domain: example.com, Type: A", [
            'exception' => $e,
            'stack' => $e->getTraceAsString(),
        ]);
    }
    

Extension Points

  1. Custom Endpoints Extend the Client class to support non-standard API calls:

    class CustomClient extends Client {
        public function customEndpoint($path, $data = []) {
            return $this->request('POST', $path, $data);
        }
    }
    
  2. Webhook Integration Use Laravel’s queue:work to process Dyn webhook payloads asynchronously:

    Route::post('/dyn-webhook', function (Request $request) {
        dispatch(new ProcessDynWebhook($request->input()));
    });
    
  3. Testing Mock the Client in PHPUnit:

    $mock = Mockery::mock(Client::class);
    $mock->shouldReceive('deleteDnsRecord')
         ->with('example.com', 'A', null, true)
         ->andReturn(true);
    $this->app->instance(Client::class, $mock);
    
  4. Soft Deletion Pattern Implement a soft-delete strategy to avoid accidental node deletions:

    $client->updateDnsRecord('example.com', 'A', '192.0.2.1', [
        'disabled' => true,
        'ttl' => 300,
    ]);
    
  5. Transaction-like Operations For critical operations, implement a rollback mechanism:

    try {
        $client->deleteDnsRecord('example.com', 'A', null, true);
        // Backup records before deletion
        Cache::put("backup_{$domain}", $client->getDnsRecords($domain), now()->addHours(1));
    } catch (\Exception $e) {
        // Restore from backup if needed
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky