This commit is contained in:
30
docs/snippets/php/installation/composer_install.php
Normal file
30
docs/snippets/php/installation/composer_install.php
Normal file
@@ -0,0 +1,30 @@
|
||||
```php title="composer_install.php"
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Installing Kreuzberg via Composer
|
||||
*
|
||||
* This snippet shows how to install the Kreuzberg PHP package using Composer.
|
||||
* The package provides the object-oriented and procedural APIs, while the
|
||||
* native extension (kreuzberg.so/.dll) must be installed separately.
|
||||
*/
|
||||
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Kreuzberg\Kreuzberg;
|
||||
|
||||
if (!extension_loaded('kreuzberg')) {
|
||||
echo "Error: kreuzberg extension is not loaded\n";
|
||||
echo "Please add 'extension=kreuzberg.so' (or .dll on Windows) to your php.ini\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "Kreuzberg extension is loaded successfully!\n";
|
||||
echo "Version: " . Kreuzberg::version() . "\n";
|
||||
|
||||
$kreuzberg = new Kreuzberg();
|
||||
echo "Kreuzberg client initialized successfully!\n";
|
||||
```
|
||||
50
docs/snippets/php/installation/extension_setup.php
Normal file
50
docs/snippets/php/installation/extension_setup.php
Normal file
@@ -0,0 +1,50 @@
|
||||
```php title="extension_setup.php"
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Setting up the Kreuzberg PHP Extension
|
||||
*
|
||||
* The Kreuzberg native extension must be installed and loaded before using the library.
|
||||
* This snippet shows how to check for the extension and provides guidance for installation.
|
||||
*/
|
||||
|
||||
if (!extension_loaded('kreuzberg')) {
|
||||
echo "Kreuzberg extension not found!\n\n";
|
||||
echo "Installation steps:\n";
|
||||
echo "1. Download the extension for your platform from:\n";
|
||||
echo " https://github.com/kreuzberg-dev/kreuzberg/releases\n\n";
|
||||
echo "2. Copy the extension to your PHP extensions directory:\n";
|
||||
echo " - Linux/macOS: kreuzberg.so\n";
|
||||
echo " - Windows: kreuzberg.dll\n\n";
|
||||
echo "3. Add to your php.ini:\n";
|
||||
echo " extension=kreuzberg.so ; Linux/macOS\n";
|
||||
echo " extension=kreuzberg.dll ; Windows\n\n";
|
||||
echo "4. Restart PHP/PHP-FPM/Apache\n\n";
|
||||
echo "5. Verify with: php -m | grep kreuzberg\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "Kreuzberg Extension Information:\n";
|
||||
echo "================================\n";
|
||||
echo "Status: Loaded\n";
|
||||
|
||||
$tesseract_available = function_exists('kreuzberg_has_tesseract') ? kreuzberg_has_tesseract() : false;
|
||||
$onnx_available = function_exists('kreuzberg_has_onnx') ? kreuzberg_has_onnx() : false;
|
||||
|
||||
echo "Tesseract OCR: " . ($tesseract_available ? "Available" : "Not available") . "\n";
|
||||
echo "ONNX Runtime: " . ($onnx_available ? "Available" : "Not available") . "\n";
|
||||
|
||||
if (!$tesseract_available) {
|
||||
echo "\nTo enable OCR functionality, install Tesseract:\n";
|
||||
echo " macOS: brew install tesseract\n";
|
||||
echo " Ubuntu/Debian: sudo apt install tesseract-ocr\n";
|
||||
}
|
||||
|
||||
if (!$onnx_available) {
|
||||
echo "\nTo enable embeddings, install ONNX Runtime:\n";
|
||||
echo " macOS: brew install onnxruntime\n";
|
||||
echo " Ubuntu/Debian: sudo apt install libonnxruntime\n";
|
||||
}
|
||||
```
|
||||
86
docs/snippets/php/installation/pie_install.php
Normal file
86
docs/snippets/php/installation/pie_install.php
Normal file
@@ -0,0 +1,86 @@
|
||||
```php title="pie_install.php"
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Installing Kreuzberg PHP Extension using PIE
|
||||
*
|
||||
* PIE (PHP Installer for Extensions) is a modern tool for installing PHP extensions.
|
||||
* This snippet shows how to install the Kreuzberg extension using PIE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Kreuzberg\Kreuzberg;
|
||||
|
||||
echo "Kreuzberg Extension Installation Check\n";
|
||||
echo "========================================\n\n";
|
||||
|
||||
if (extension_loaded('kreuzberg')) {
|
||||
echo "✓ Kreuzberg extension is loaded\n";
|
||||
echo " Version: " . Kreuzberg::version() . "\n\n";
|
||||
|
||||
$info = [];
|
||||
ob_start();
|
||||
phpinfo(INFO_MODULES);
|
||||
$phpinfo = ob_get_clean();
|
||||
|
||||
if (preg_match('/kreuzberg/i', $phpinfo)) {
|
||||
echo "✓ Extension info available via phpinfo()\n\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$kreuzberg = new Kreuzberg();
|
||||
echo "✓ Kreuzberg client initialized successfully\n\n";
|
||||
|
||||
echo "Installation complete!\n";
|
||||
echo "You can now use Kreuzberg in your PHP applications.\n";
|
||||
} catch (Exception $e) {
|
||||
echo "✗ Error initializing Kreuzberg: {$e->getMessage()}\n";
|
||||
}
|
||||
} else {
|
||||
echo "✗ Kreuzberg extension is not loaded\n\n";
|
||||
|
||||
echo "Troubleshooting:\n";
|
||||
echo "================\n";
|
||||
echo "1. Make sure PIE installation completed successfully\n";
|
||||
echo "2. Check that extension is enabled in php.ini\n";
|
||||
echo "3. Restart your web server/PHP-FPM\n";
|
||||
echo "4. Run: php -m | grep kreuzberg\n";
|
||||
echo "5. Check error logs for loading issues\n\n";
|
||||
|
||||
echo "Manual Installation:\n";
|
||||
echo "===================\n";
|
||||
echo "If PIE installation fails, try manual installation:\n";
|
||||
echo "1. Download extension from GitHub releases\n";
|
||||
echo "2. Copy .so/.dll file to PHP extension directory\n";
|
||||
echo "3. Add 'extension=kreuzberg.so' to php.ini\n";
|
||||
echo "4. Restart PHP\n";
|
||||
}
|
||||
|
||||
echo "\n\nPIE Commands Reference:\n";
|
||||
echo "=======================\n";
|
||||
echo "Install extension: pie install kreuzberg/kreuzberg-ext\n";
|
||||
echo "Install specific version: pie install kreuzberg/kreuzberg-ext:4.2.7\n";
|
||||
echo "List installed: pie list\n";
|
||||
echo "Update extension: pie update kreuzberg/kreuzberg-ext\n";
|
||||
echo "Uninstall: pie uninstall kreuzberg/kreuzberg-ext\n";
|
||||
echo "Show info: pie info kreuzberg/kreuzberg-ext\n";
|
||||
|
||||
echo "\n\nNext Steps:\n";
|
||||
echo "===========\n";
|
||||
echo "1. Install Composer package: composer require kreuzberg/kreuzberg\n";
|
||||
echo "2. Install optional dependencies:\n";
|
||||
echo " - Tesseract OCR: brew install tesseract (macOS) or apt install tesseract-ocr (Linux)\n";
|
||||
echo " - ONNX Runtime: brew install onnxruntime (macOS) or apt install libonnxruntime (Linux)\n";
|
||||
echo "3. Start extracting documents!\n";
|
||||
```
|
||||
81
docs/snippets/php/installation/requirements_check.php
Normal file
81
docs/snippets/php/installation/requirements_check.php
Normal file
@@ -0,0 +1,81 @@
|
||||
```php title="requirements_check.php"
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* System Requirements Check
|
||||
*
|
||||
* Verify that your system meets all requirements for running Kreuzberg.
|
||||
*/
|
||||
|
||||
echo "Kreuzberg System Requirements Check\n";
|
||||
echo "====================================\n\n";
|
||||
|
||||
$requirements_met = true;
|
||||
|
||||
echo "PHP Version: " . PHP_VERSION;
|
||||
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
|
||||
echo " ✓ (>= 8.1.0 required)\n";
|
||||
} else {
|
||||
echo " ✗ (>= 8.1.0 required)\n";
|
||||
$requirements_met = false;
|
||||
}
|
||||
|
||||
$required_extensions = ['json', 'mbstring'];
|
||||
foreach ($required_extensions as $ext) {
|
||||
echo "Extension '$ext': ";
|
||||
if (extension_loaded($ext)) {
|
||||
echo "✓ Loaded\n";
|
||||
} else {
|
||||
echo "✗ Missing\n";
|
||||
$requirements_met = false;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Extension 'kreuzberg': ";
|
||||
if (extension_loaded('kreuzberg')) {
|
||||
echo "✓ Loaded\n";
|
||||
} else {
|
||||
echo "✗ Missing\n";
|
||||
$requirements_met = false;
|
||||
}
|
||||
|
||||
$memory_limit = ini_get('memory_limit');
|
||||
echo "\nMemory Limit: $memory_limit";
|
||||
$memory_bytes = return_bytes($memory_limit);
|
||||
if ($memory_bytes >= 128 * 1024 * 1024) {
|
||||
echo " ✓ (>= 128M recommended)\n";
|
||||
} else {
|
||||
echo " ! (>= 128M recommended for large documents)\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
if ($requirements_met) {
|
||||
echo "✓ All requirements met! You're ready to use Kreuzberg.\n";
|
||||
} else {
|
||||
echo "✗ Some requirements are not met. Please install missing components.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PHP memory limit notation to bytes
|
||||
*/
|
||||
function return_bytes(string $val): int
|
||||
{
|
||||
$val = trim($val);
|
||||
$last = strtolower($val[strlen($val) - 1]);
|
||||
$val = (int) $val;
|
||||
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
$val *= 1024;
|
||||
case 'm':
|
||||
$val *= 1024;
|
||||
case 'k':
|
||||
$val *= 1024;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user