beyondcode / herd-community

85 stars 1 forks source link

[Bug]: PDOException: Could not find driver when running scheduled tasks on Herd #931

Closed ketencek closed 1 month ago

ketencek commented 2 months ago

Platform

macOS

Operating system version

nacOS Sonoma 14.5 (23F79)

System architecture

ARM64 (M1, M2, etc)

Herd Version

Version: 1.9.1 (Build: 31)

PHP Version

PHP Version 8.3.9 Build Date Jul 8 2024 12:00:39 NTS

Bug description

•   Laravel version: 11
•   SQL Server version: 2017
•   Driver: pdo_sqlsrv 5.12.0

Description:

I am facing an issue when running scheduled tasks using Herd on my Laravel project. The problem occurs specifically with SQL Server connections. Although I can successfully connect to the database using Tinker and the web interface, I receive a “could not find driver” error when running a scheduled task.

•   Error Message

[previous exception] [object] (PDOException(code: 0): could not find driver at /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65)

Steps to reproduce

  1. Connect to the database using Tinker (works fine).
    1. Set up a scheduled task that executes a command involving SQL Server.
    2. Run the scheduled task using php artisan schedule:run.
    3. Observe the “could not find driver” error. • Additional Details: When I check the PHP configuration using php --ini, it shows:

Configuration File (php.ini) Path: /lib Loaded Configuration File: (none) Scan for additional .ini files in: /Users/hanifeoglu/Library/Application Support/Herd/config/php/83/ Additional .ini files parsed: /Users/hanifeoglu/Library/Application Support/Herd/config/php/83/php.ini

this.

Expected Behavior:

The scheduled task should be able to connect to the SQL Server without issues, just as it does in Tinker and the web interface.

Questions:

1.  Could the issue be related to the PHP configuration not loading the correct php.ini file when running scheduled tasks?
2.  Is there any specific configuration required in Herd to ensure the correct drivers are loaded during scheduled tasks?

Any help or guidance would be greatly appreciated!

Relevant log output

[previous exception] [object] (PDOException(code: 0): could not find driver at /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65)
[stacktrace]
#0 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(65): PDO->__construct('dblib:host=192....', 'ketreport', Object(SensitiveParameterValue), Array)
#1 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(44): Illuminate\\Database\\Connectors\\Connector->createPdoConnection('dblib:host=192....', 'ketreport', 'Ketencek@1953', Array)
#2 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connectors/SqlServerConnector.php(32): Illuminate\\Database\\Connectors\\Connector->createConnection('dblib:host=192....', Array, Array)
#3 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(185): Illuminate\\Database\\Connectors\\SqlServerConnector->connect(Array)
#4 [internal function]: Illuminate\\Database\\Connectors\\ConnectionFactory->Illuminate\\Database\\Connectors\\{closure}()
#5 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(1231): call_user_func(Object(Closure))
#6 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(1267): Illuminate\\Database\\Connection->getPdo()
#7 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(512): Illuminate\\Database\\Connection->getReadPdo()
#8 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(407): Illuminate\\Database\\Connection->getPdoForSelect(true)
#9 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(812): Illuminate\\Database\\Connection->Illuminate\\Database\\{closure}('EXEC sp_KetTvMa...', Array)
#10 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(779): Illuminate\\Database\\Connection->runQueryCallback('EXEC sp_KetTvMa...', Array, Object(Closure))
#11 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(398): Illuminate\\Database\\Connection->run('EXEC sp_KetTvMa...', Array, Object(Closure))
#12 /Users/hanifeoglu/Herd/websocket-reverb/app/Console/Commands/UpdateExampleEvent.php(44): Illuminate\\Database\\Connection->select('EXEC sp_KetTvMa...')
#13 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Console\\Commands\\UpdateExampleEvent->handle()
#14 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#15 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#16 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#17 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Container/Container.php(690): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#18 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\\Container\\Container->call(Array)
#19 /Users/hanifeoglu/Herd/websocket-reverb/vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#20 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#21 /Users/hanifeoglu/Herd/websocket-reverb/vendor/symfony/console/Application.php(1047): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 /Users/hanifeoglu/Herd/websocket-reverb/vendor/symfony/console/Application.php(316): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\UpdateExampleEvent), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 /Users/hanifeoglu/Herd/websocket-reverb/vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(197): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#25 /Users/hanifeoglu/Herd/websocket-reverb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1203): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#26 /Users/hanifeoglu/Herd/websocket-reverb/artisan(13): Illuminate\\Foundation\\Application->handleCommand(Object(Symfony\\Component\\Console\\Input\\ArgvInput))
#27 {main}
"}
sschlein commented 2 months ago

I try to set up sql server and recreate the issue in the next days, it's definitely weird that it works in all cases except in scheduled tasks.

mpociot commented 1 month ago

pdo_sqlsrv is actually not an extension that we ship with Herd, so either:

Regardless, Herd currently does not ship sqlserv out of the box