Skip to content

⚡ InstallWithAPCu Install dependencies with APCu autoloader cache enabled

🔍 InstallWithAPCu installs project dependencies with the --apcu-autoloader option, enabling APCu caching for the autoloader to improve class-loading performance, equivalent to running composer install --apcu-autoloader.

📋 Signature

go
func (c *Composer) InstallWithAPCu() error

📥 Parameters

ParameterTypeDescription
NoneThis method takes no parameters

📤 Return value

Return valueTypeDescription
First return valueerrorReturned when an error occurs during installation; nil on success

📝 Example

go
package main

import (
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.NewComposer()
	if err != nil {
		log.Fatalf("Failed to create Composer instance: %v", err)
	}

	if err := comp.InstallWithAPCu(); err != nil {
		log.Fatalf("Failed to install dependencies: %v", err)
	}
	log.Println("Dependencies installed (APCu cache enabled)")
}

🚀 Advanced

  • ⚠️ Prerequisite: the APCu extension must be installed in the runtime environment, otherwise this option has no effect; you can confirm whether apcu is present in the php -m output.
  • 🧪 It yields the most benefit in development environments where the application is frequently restarted; in production it is typically combined with --optimize-autoloader — you can use InstallWithOptions to pass both apcu and optimize-autoloader at once.
  • 🔁 If you also need to skip development dependencies, use Install(true, true) or combine multiple options via InstallWithOptions.
  • 🔗 Under the hood it calls c.Run("install", "--apcu-autoloader"); the working directory and Composer path are determined by the Composer instance configuration.

Released under the MIT License