PHPackages                             jayeshmepani/swiss-ephemeris-ffi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jayeshmepani/swiss-ephemeris-ffi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jayeshmepani/swiss-ephemeris-ffi
================================

Complete 100% 1:1 PHP FFI Wrapper for the Swiss Ephemeris C Library - Direct C function calls with zero abstraction for maximum astronomical precision

v1.0.0(1mo ago)03↑2900%AGPL-3.0-or-laterPHPPHP ^8.3CI passing

Since Mar 24Pushed 1mo agoCompare

[ Source](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP)[ Packagist](https://packagist.org/packages/jayeshmepani/swiss-ephemeris-ffi)[ Docs](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP)[ GitHub Sponsors](https://github.com/sponsors/jayeshmepani)[ RSS](/packages/jayeshmepani-swiss-ephemeris-ffi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Swiss Ephemeris PHP FFI
=======================

[](#swiss-ephemeris-php-ffi)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9a008d5210beed330dc6be46ba671a2aae632521fc5194057e0613d7e45631e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a61796573686d6570616e692f73776973732d657068656d657269732d6666692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jayeshmepani/swiss-ephemeris-ffi)[![Total Downloads](https://camo.githubusercontent.com/3afe2de393cb06d3314717176ced3c7e705a8a94d052fea55c86d4b4615c35ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a61796573686d6570616e692f73776973732d657068656d657269732d6666692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jayeshmepani/swiss-ephemeris-ffi)[![PHP Version Require](https://camo.githubusercontent.com/5e60ddd1455dcc20e0a0c66d7c5a29a65fd46c38796abbd9b98141fa80a0d676/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a61796573686d6570616e692f73776973732d657068656d657269732d6666693f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jayeshmepani/swiss-ephemeris-ffi)[![License](https://camo.githubusercontent.com/d7f6b312f3430600fac3c467365ddf343ed6f4002e1a5669482013e6390fe30e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a61796573686d6570616e692f53776973732d457068656d657269732d5048503f7374796c653d666c61742d737175617265)](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP/blob/main/LICENSE)[![Tests](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP/actions/workflows/tests.yml/badge.svg)](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP/actions/workflows/tests.yml)[![Release Prebuilt Libraries](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP/actions/workflows/release-prebuilt-libs.yml/badge.svg)](https://github.com/jayeshmepani/Swiss-Ephemeris-PHP/actions/workflows/release-prebuilt-libs.yml)

A strict, **100% precise, exact 1:1 FFI mapping** of the [Swiss Ephemeris](https://www.astro.com/swisseph/) C library for PHP 8.3+.

This wrapper gives you the exact API surface, structs, macro constants, and FFI pointers as defined in the original `swephexp.h`. Zero tolerance for omissions or high-level abstractions: every single calculation, planet ID, house system, sidereal mode, and eclipse check is strictly preserved for **maximum astronomical precision**.

🎯 Unique Value Proposition
--------------------------

[](#-unique-value-proposition)

**This is the ONLY PHP implementation that:**

- ✅ Uses **PHP FFI** (no PHP extension compilation required)
- ✅ Links to **shared library** (libswe.\* per OS)
- ✅ Achieves **100% function coverage** (all 200+ swe\_\* functions)
- ✅ Maintains **1:1 mapping** with C library
- ✅ Preserves **exact C library precision** (no CLI parsing, no text output)
- ✅ Works with **Laravel, Symfony, or plain PHP**

Unlike other PHP packages that wrap the `swetest` CLI binary, this package calls the C functions directly via FFI - just like the Python (pyswisseph) and Node.js (swisseph) bindings.

Features
--------

[](#features)

- **100% C Library Coverage**: Every single exported function from `swephexp.h`.
- **Zero Loss / Round-offs**: Arguments and return values are explicitly `double` and `int32` via raw FFI arrays/pointers.
- **Native Performance**: Direct C calls via PHP's `ext-ffi` - no process spawning, no text parsing.
- **Prebuilt Shared Libraries**: Auto-downloads the correct binary on install (Linux/macOS/Windows) when available.
- **Laravel Ready**: Optional Service Provider and Facade included.
- **Framework Agnostic**: Works with Laravel, Symfony, CodeIgniter, or plain PHP.

Installation
------------

[](#installation)

```
composer require jayeshmepani/swiss-ephemeris-ffi
```

> **Note:** PHP FFI must be installed and enabled.

### FFI Requirement (All Platforms)

[](#ffi-requirement-all-platforms)

You need **PHP 8.3+ with `ext-ffi`**.

#### Check if FFI is Available

[](#check-if-ffi-is-available)

**Linux/macOS:**

```
php -m | grep -i ffi
```

**Windows (PowerShell):**

```
php -m | Select-String -Pattern "ffi"
```

**Windows (CMD):**

```
php -m | findstr /i "ffi"
```

#### Platform-Specific Setup

[](#platform-specific-setup)

**🐧 Linux****Ubuntu/Debian:**

```
sudo apt install php8.3-ffi
# or for PHP 8.4
sudo apt install php8.4-ffi
```

**CentOS/RHEL/Fedora:**

```
sudo dnf install php-ffi
# or
sudo yum install php-ffi
```

**Enable FFI in php.ini:**

```
sudo nano /etc/php/8.3/cli/php.ini
# or
sudo nano /etc/php/8.3/apache2/php.ini  # for Apache
```

Add or ensure **BOTH** lines are present (not commented):

```
extension=ffi
ffi.enable=1
```

**🍎 macOS****Homebrew:**

```
# PHP from Homebrew includes FFI by default
brew install php@8.3
```

**Enable FFI in php.ini:**

```
nano $(php --ini | grep "Loaded Configuration" | awk '{print $4}')
```

Add or ensure **BOTH** lines are present (not commented):

```
extension=ffi
ffi.enable=1
```

**🪟 Windows**FFI is included with PHP 8.3+ for Windows.

**Enable FFI in php.ini:**

1. Locate your `php.ini` file (usually in `C:\php\php.ini`)
2. Open it in a text editor (as Administrator)
3. Find the lines `;extension=ffi` and `;ffi.enable=1` and remove the semicolons, or add:

```
extension=ffi
ffi.enable=1
```

4. Restart your web server if using Apache/IIS

**Verify installation:**

```
php -m | Select-String -Pattern "ffi"
```

**🔧 Custom PHP Build**If you compiled PHP from source, ensure FFI was enabled:

```
php --ini | grep -i ffi
```

If missing, recompile PHP with:

```
./configure --with-ffi
# or
./configure --enable-ffi
make
sudo make install
```

**Note:** When building from source, `extension=ffi` may not be needed if FFI is compiled statically. Only `ffi.enable=1` would be required in php.ini.

#### Enable FFI in php.ini

[](#enable-ffi-in-phpini)

For all platforms, ensure **BOTH** of these settings are present in your `php.ini`:

```
; 1. Load the FFI extension (required on most systems)
extension=ffi

; 2. Enable FFI functionality
ffi.enable=1
; or for better performance with preload
ffi.enable=preload
; or ffi.enable=true (also works)
```

**Important:** Both lines are typically required:

- `extension=ffi` - Loads the FFI extension module
- `ffi.enable=1` (or `true`) - Enables FFI functionality

**Verify FFI is properly configured:**

```
# Check if FFI extension is loaded
php -m | grep -i ffi

# Or create a PHP file to verify
php -r "echo extension_loaded('ffi') ? 'FFI loaded ✓' : 'FFI not loaded ✗';"
php -r "echo ini_get('ffi.enable') ? 'FFI enabled ✓' : 'FFI not enabled ✗';"
```

**Restart your web server** after making changes to `php.ini`:

```
# Apache
sudo systemctl restart apache2
# or
sudo systemctl restart httpd

# Nginx + PHP-FPM
sudo systemctl restart php8.3-fpm
# or
sudo systemctl restart php-fpm

# Windows (IIS/Apache)
# Restart the web server service from Services panel or use:
iisreset
```

### Prebuilt Libraries (Zero-Setup)

[](#prebuilt-libraries-zero-setup)

On `composer install`, the package will attempt to download the correct prebuilt library for your OS/CPU from GitHub Releases.

#### Platform-Specific Library Assets

[](#platform-specific-library-assets)

**🐧 Linux****x86\_64 (Intel/AMD):**

- Asset: `libswe-linux-x64.tar.gz`
- Library: `libswe.so`
- Architecture: x86\_64

**ARM64 (Raspberry Pi, AWS Graviton, etc.):**

- Asset: `libswe-linux-arm64.tar.gz`
- Library: `libswe.so`
- Architecture: aarch64

**Manual Installation:**

```
# Download and extract
tar -xzf libswe-linux-x64.tar.gz
sudo cp libswe.so /usr/local/lib/
sudo ldconfig
```

**🍎 macOS****Intel (x86\_64):**

- Asset: `libswe-macos-x64.tar.gz`
- Library: `libswe.dylib`
- Architecture: x86\_64

**Apple Silicon (M1/M2/M3):**

- Asset: `libswe-macos-arm64.tar.gz`
- Library: `libswe.dylib`
- Architecture: arm64

**Manual Installation:**

```
# Download and extract
tar -xzf libswe-macos-x64.tar.gz
sudo cp libswe.dylib /usr/local/lib/
# or for Homebrew PHP
sudo cp libswe.dylib $(brew --prefix)/lib/
```

**🪟 Windows****x86\_64 (64-bit):**

- Asset: `libswe-windows-x64.zip`
- Library: `swe.dll`
- Architecture: x86\_64

**Manual Installation:**

```
# Extract the ZIP
Expand-Archive libswe-windows-x64.zip -DestinationPath C:\php\ext\
# Add to PATH or copy to system directory
```

**Note:** Ensure the DLL is in your PHP extension path or system PATH.

#### Environment Variables

[](#environment-variables)

To customize library loading:

- **`SWISSEPH_SKIP_DOWNLOAD=1`**: Disable auto-download on install
- **`SWISSEPH_LIBRARY_PATH=/path/to/libswe.so`**: Specify custom library path

Example in `.env` or shell:

```
export SWISSEPH_LIBRARY_PATH=/usr/local/lib/libswe.so
```

### Swiss Ephemeris Version

[](#swiss-ephemeris-version)

This package tracks the **latest version** of the [Swiss Ephemeris C library](https://github.com/aloistr/swisseph):

- **Current upstream version**: v2.10.03+ (latest commit from master branch)
- **Last upstream commit**: March 11, 2026 - "fixed old rounding bug in swe\_split\_deg()"
- **Latest release tag**: v2.10.03 (September 9, 2022)
- **Development branch**: `master` (actively maintained)

**Your package always uses the latest version** when you run:

```
composer build
# or
bash build/compile-linux.sh
```

This downloads the latest commit from the official Swiss Ephemeris repository and compiles it into the OS-specific shared library.

### If you need to rebuild the library manually:

[](#if-you-need-to-rebuild-the-library-manually)

```
composer build
# or (OS specific)
bash build/compile-linux.sh
bash build/compile-macos.sh
# Windows (PowerShell 5.1 or Core 7+)
pwsh -File build/compile-windows.ps1
# or
powershell -ExecutionPolicy Bypass -File build/compile-windows.ps1
```

Ephemeris Files
---------------

[](#ephemeris-files)

For precise planetary, lunar, and asteroidal calculations, download the official `.se1` ephemeris files:

1. Download files from
2. Place them in your project (e.g., `/ephe`).
3. Point the library to them using `$sweph->swe_set_ephe_path('/path/to/ephe');`

*Many beginners forget this step, resulting in less accurate "Moshier" calculations being used as a fallback.*

Usage
-----

[](#usage)

Because this is a **1:1 strict binding**, you must pass arguments via FFI pointers (`CData`) just as you would in C.

### Tropical Zodiac (Sun Position)

[](#tropical-zodiac-sun-position)

```
