承接 omaralalwi/laravel-py 相关项目开发

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

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

omaralalwi/laravel-py

Composer 安装命令:

composer require omaralalwi/laravel-py

包简介

Laravel wrapper for php-py package, to seamless enabling secure and efficient execution of Python scripts within PHP applications.

README 文档

README

Laravel wrapper for php-py package package, to Seamless enabling secure and efficient execution of Python scripts within Laravel applications without spread multiple applications and or setup API.

📌 Table of Contents

Requirements

  • PHP 8.1+ .
  • python3 must be installed in server .

Installation 🛠️

You can install the package via Composer:

composer require omaralalwi/laravel-py

Publishing Configuration File

php artisan vendor:publish --tag=laravel-py

🚀 Quick Start

  1. 📂 Create a folder for scripts, e.g., phpPyScripts in your project root directory.
  2. 📝 Create a Python script file (.py extension) and write Python code. See this script examples.
  3. 🔧 make script file executable, chmod +x script_file_path .

⚡ Easy Usage

<?php

use LaravelPy;

class LaravelPyController
{
  public function testLaravelPy() {
      $laravelPy = app(LaravelPy::class);
      $script = 'total_calculator.py';
      $arguments = [10, 20, 30];
          
      try {
           $result = $laravelPy
              ->loadScript($script)
              ->withArguments($arguments)
              ->run();
              
          print_r($result); // 60.0
      } catch (Exception $e) {
          echo "Error: " . $e->getMessage();
      }
  }
}

🔥 Advanced Usage

<?php

use LaravelPy;
use Omaralalwi\PhpPy\Managers\ConfigManager;

class LaravelPyController
{
  public function testLaravelPy() 
  {
     try {
        $laravelPy = app(LaravelPy::class);
        $script = 'advance_example.py';

        $numbers = [2,4, 5,7,9];

        $config = new ConfigManager([
            'scripts_directory' => 'phpPyScripts',
            'python_executable' => '/usr/bin/python3',
            'max_timeout' => 120,
        ]);

        $result = $laravelPy
            ->setConfig($config)
            ->loadScript($script)
            ->withArguments($numbers)
            ->withEnvironment(['FIRST_ENV_VAR' => 10, 'SECOND_ENV_VAR' => 'second var value'])
            ->timeout(60)
            ->asJson()
            ->run();

        print_r(json_encode($result));
    } catch (\Exception $e) {
        print_r("Error: " . $e->getMessage());
    }
  }
}

✨ Features

🔐 Secure Execution

  • Path Validation ✅ Ensures scripts are within allowed directories.
  • Argument & Environment Validation 🔍 Restricts unauthorized input.
  • Timeout Control ⏳ Prevents long-running scripts.
  • black list for these vars PATH,PYTHONPATH,LD_LIBRARY_PATH,LD_PRELOAD,PYTHONHOME, can not passed .
  • Uses proc_open as an alternative to shell_exec.

🔧 Flexible Configuration

  • Centralized settings via ConfigManager.
  • Customizable execution parameters.

📤 Output Handling

  • Supports JSON parsing.
  • Captures and reports script errors.

🚨 Error Management

  • Detailed exception handling for debugging.
  • Standardized error reporting.

🔌 Extensibility

  • Modular execution through CommandExecutor.
  • Customizable for advanced use cases.

Important Critical Note:

❌ Never pass user-controlled input directly script, just pass scripts that you will need as a administrator (Just from Your side) .

📋 Changelog

See detailed release notes in CHANGELOG.md 📜

🧪 Testing

./vendor/bin/pest

🔒 Security

Report Vulnerabilities: Contact omaralwi2010@gmail.com 📩

🤝 Contributors

A huge thank you to these amazing people who have contributed to this project! 🎉💖

Omar AlAlwi
Omar AlAlwi

🏆 Creator

Want to contribute? Check out the contributing guidelines and submit a pull request! 🚀

📄 License

This package is open-source software licensed under the MIT License. 📜

omaralalwi/laravel-py 适用场景与选型建议

omaralalwi/laravel-py 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 51, 最近一次更新时间为 2025 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 omaralalwi/laravel-py 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 51
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-08