PHP extensions (like `mongodb`) is not loading for a specific PHP version (e.g., 8.1) enabled by Laravel Herd on macOS?

I’m using Laravel Herd on macOS with multiple PHP versions managed by Herd (7.4, 8.1, 8.2, 8.3). I verified that PHP 8.1 is active using php -v.

Following the Herd documentation for adding extensions (https://herd.laravel.com/docs/1/advanced-usage/additional-extensions), I installed the mongodb extension using brew install php and sudo pecl install mongodb.

I found mongodb.so in two locations:

  • /opt/homebrew/lib/php/pecl/20230831/mongodb.so
  • /opt/homebrew/Cellar/php/8.3.4/pecl/20230831/mongodb.so

However, upon installation, the extension line extension=/opt/homebrew/lib/php/pecl/20230831/mongodb.so was automatically added to the Herd php.ini for the 8.3 version. And mongodb extension is showing fine on php 8.3 nad listed after running php -m, even though the active version is php 8.1.

As I need the extension on php 8.1, When I manually added the same line to the Herd php.ini for the 8.1 version, I encountered the error:

Warning: PHP Startup: Unable to load dynamic library 
'/opt/homebrew/lib/php/pecl/20230831/mongodb.so'

Can anyone give some idea on the recommended approach to install php extension for individual php version enabled by laravel herd?

no connection to the database with PHP 8.2 [duplicate]

I have a class that works with PHP 8.0 but not with PHP 8.2

    if(!defined('pageclassconst')) {
        die('You cannot access this file directly!');
    }

    class connectionClass extends mysqli {

        private $host="localhost",$dbname="DB_Name",$dbpass="DB_Pass",$dbuser="DB_User";
        public $con;

        public function __construct() {
            if(!$this->con=$this->connect($this->host, $this->dbuser, $this->dbpass, $this->dbname)) {
                $this->con=$this->set_charset("utf8");
            } else {
                echo "Ein interner Fehler ist aufgetreten!";
                exit;
            }
        }
    }

Where is the error now?
Thanks for help.

php tags in success messages [duplicate]

I’ve designed a website with a forum with users, different categories and posts!For that, I already established a mysql database via localhost showing users, categories and posts tables!
The categorie_id of the posts table is interwoven with the categorie title in the categories table as foreign key!

How could I now show the category title from categories table in success message of added posts on my website manage posts table (see picture below)?

I want it to show sthg like this in the success message: “New Music (=category title) post was successfully added!”

I tried it like this, but it didn’t show the category title in the success message (please, take a closer look into the row with $_SESSION:[‘add-post-success’] = ….):

Manage Posts Table Screenshot

categories database table
posts db table

 // insert post into database
        $query = "INSERT INTO posts (title, body, thumbnail, category_id, author_id, is_featured) VALUES ('$title', '$body', '$thumbnail_name', $category_id, $author_id, $is_featured)";
        $result = mysqli_query($connection, $query);

        if(!mysqli_errno($connection)) {
            $_SESSION['add-post-success'] = "New <php= {$category['title']} ?> post added successfully";
            header('location: ' . ROOT_URL . 'admin/');
            die();
        }

Amazon SP-API Access token is missing error

I am getting the following result from an SP-API call using CURL within PHP. It is a private app created in seller central and all permissions have been granted. We are just trying to retrieve our own data.

Array (
    [errors] => Array
        (
            [0] => Array
                (
                    [code] => Unauthorized
                    [message] => Access to requested resource is denied.
                    [details] => Access token is missing in the request header.
                )

        )

)

Access token is retrieved with a refresh token and included, here is the code. amazonApiUrl is https://sellingpartnerapi-na.amazon.com

$headers = array(
            'Content-Type: application/json',
            'Authorization: Bearer '.$accessToken
        );

        $curl = curl_init($this->amazonApiUrl."/catalog/2022-04-01/items?marketplaceIds=ATVPDKIKX0DER");

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_USERAGENT, 'XXXXXXXXX-app/v1');

        $response = curl_exec($curl);

The access token exists and has been retrieved from https://api.amazon.com/auth/o2/token#

What can be wrong ?

I was expecting our products list but getting the above error.

What could create unix sockets in PHP 8.2 as a side-effect?

In two of our many PHP pods (we’re running under Kubernetes) we have a problem with a Unix socket leak. Our PHP CLI process seems to be opening and not closing many unix sockets, until in an unrelated location PHP crashes with PHP Warning: stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE.

Other pods that we have also have some UNIX sockets open, but in small numbers so it’s not a problem.

The perplexing thing is that we’re not using UNIX sockets for anything. All communication with other processes is purely through TCP/IP. All the sockets are:

  • In ESTABLISHED state
  • ss -x says that there have been no data either sent or received on these sockets
  • They do not have a file in the filesystem
  • netstat says that they all have a RefCount of 3, if it means anything
  • ss -xp also shows, that both ends of each socket are held by the same (one and only) PHP process.

So… for some reason the PHP program is creating UNIX sockets, holding them open, holding on to both ends of that socket (two different file descriptors), and not letting them go.

In addition, there are no calls to stream_socket_pair or socket_create_pair in the code.

What I gather from this is that these sockets are created as a side-effect of some other PHP built-in function that I’m using. CURL is the primary suspect here, but it’s also used plenty in other pods without issues. In fact I can’t think of anything that these two pods are doing which others aren’t.

What built-in PHP functions (including functions in extensions that come bundled by default with PHP) could result in an unintentional creation of a UNIX socket pair?

Added:

xx -xp looks like:

# ss -xp
Netid               State               Recv-Q               Send-Q                             Local Address:Port                                  Peer Address:Port                   Process
u_str               ESTAB               0                    0                                              * 481304571                                        * 481304572               users:(("php",pid=7,fd=494))
u_str               ESTAB               0                    0                                              * 480934363                                        * 480934362               users:(("php",pid=7,fd=289))
u_str               ESTAB               0                    0                                              * 480899260                                        * 480899259               users:(("php",pid=7,fd=255))
u_str               ESTAB               0                    0                                              * 480853228                                        * 480853229               users:(("php",pid=7,fd=207))
u_str               ESTAB               0                    0                                              * 478659551                                        * 478659550               users:(("php",pid=7,fd=82))
u_str               ESTAB               0                    0                                              * 481263776                                        * 481263775               users:(("php",pid=7,fd=484))
u_str               ESTAB               0                    0                                              * 481014545                                        * 481014546               users:(("php",pid=7,fd=339))
u_str               ESTAB               0                    0                                              * 480847844                                        * 480847845               users:(("php",pid=7,fd=221))
u_str               ESTAB               0                    0                                              * 479446282                                        * 479446283               users:(("php",pid=7,fd=185))
u_str               ESTAB               0                    0                                              * 479430966                                        * 479430965               users:(("php",pid=7,fd=162))
u_str               ESTAB               0                    0                                              * 481391710                                        * 481391711               users:(("php",pid=7,fd=515))
u_str               ESTAB               0                    0                                              * 481013994                                        * 481013995               users:(("php",pid=7,fd=352))
u_str               ESTAB               0                    0                                              * 480884372                                        * 480884373               users:(("php",pid=7,fd=233))
.... many, may more lines ...

laravel foreach loop through an array in blade

I have an array which I would like to output in the edit template in a foreach loop.
But I get an error cannot access offset of type string on string

In blade I have this:

@foreach ($post->cage as $c  )

        <div data-repeater-item="">
          <div class="form-group">
            <label class="col-sm-1 control-label">Make</label>

    <label class="col-sm-1 control-label">Comment</label>
            <div class="col-sm-2">
                   <input type="text" name="cage[1][comment]" value="{{ $c['comment'] }}" class="form-control">
            </div>
          </div>
        </div>

@endforeach

The controller is very basic

/**
 * Show the form for editing the specified resource.
 */
public function edit(string $id): Response
{
    
    return response()->view('post.edit', [
        'post' => Posts::findOrFail($id),
    ]);
}

a vardump gives this

array(3) { ["level"]=> string(6) "middle" ["comment"]=> string(4) "joe2" [0]=> array(2) { ["level"]=> string(6) "middle" ["comment"]=> string(4) "joe2" } }

Any idea how to make the foreach to get the value?
Do I have to add something in the controller? decode or something?
Thanks in advance

Extra edit.
Cage is a text field which can store an array

   /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('posts', function (Blueprint $table) {

    $table->text('zone')->nullable();
        $table->text('cage')->nullable(); 
        });
    }

In the model file

 protected $casts = [
    'cage' => 'array'
];

Zabbix Custom Widget – Time selector

I am currently creating a custom Zabbix widget module, to visualize some data.

But got a bit stuck in how i can get the time selector period from the dashboard settings. (Top of the dashboard)

Do anyone have an idea where i can look this up ? Or could provide an example on how to ?
And also, i haven’t been able to find a proper documentation page with the Widget / module development API’s, in zabbix. Does there exist anything else than the Create a widget from the zabbix webpage (tutorial) ?

I expect to be able to get the to and from time defined in the timeselector in the top of the dashboard page.

While deploying laravel project on bluehost shared hosting’s addon domain, but I am getting “403 forbidden” error

While deploying laravel project on bluehost shared hosting’s addon domain, but I am getting “403 forbidden” error:

My hosting folder structure as below:

public_html:

app1 (main domain)
 |__app1 folders/files
laravelapp (addon domain)
 |__laravelapp folders/files
      |__app
      |__public
      |__other folders/files etc

Now I have fillup all “.env” file parameters including database also.

Also I have given required permission to the folders.

Also I have hit mulitple laravel cache clearing commands.

“.htacess” file inside public folder as below:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    //Added following "IfModule tag" for setup
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /laravelapp/public
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

But I am getting “403 forbidden” error for that laravel application.

Please help to resolve above issue.

Unexpected column in the database

I’m creating dynamic database from form values but when I run it, it adds extra empty column name as form_id.

            switch ($_POST["form_id"]) { #replaced column names in database cus i'm creating 2 dif database
                case 'kitap':
                    if($sutun_degeri == $form_isim){
                        $sutun_adi = 'kitap_isim'; 
                    }elseif($sutun_degeri == $form_konu){
                        $sutun_adi = 'kitap_konu'; 
                    }
                    break;
                case 'film':
                    if($sutun_degeri == $form_isim){
                        $sutun_adi = 'film_isim'; 
                    }elseif($sutun_degeri == $form_konu){
                        $sutun_adi = 'film_konu'; 
                    }
                    break;
                default:
                    break;
            }
            $sql .= "$sutun_adi VARCHAR($uzunluk), ";

database view

That code block on the top is inside of this foreach (if it will give a tip).

foreach ($form_veri as $sutun_adi => $sutun_degeri) {
            #$sql .= "$sutun_adi VARCHAR(255), ";
            $uzunluk = 0;
            if ($sutun_degeri === $form_isim) {
                $uzunluk = 100;
            }
            elseif($sutun_degeri === $form_konu){
                $uzunluk = 255;
            }

I couldnt remove the empty form_id column so I tried to customize it as Primary Key but it took form_id variable’s value as column name and made a new column.

$sql .= $form_tipi . " INT AUTO_INCREMENT PRIMARY KEY, ";

database view

This empty column is coming from there. I created this hidden input because I have 2 different forms that creates 2 different database tables. It makes separation between forms.

<form method="post" action="index.php">
   <input type="hidden" name="form_id" value="kitap">

design view

database view

WHISE API into a Laravel project

how can I integrate the WHISE API into a Laravel project and display real estate from the whise provider on my Laravel website? I’m trying to solve a problem on my Laravel project and I’m expecting effective solutions. Yours ideas go help me

Laravel HTTP Client multiple times the same key for JSON Post-Data

I want to send a JSON post to an API using the Laravel HTTP function. This is working great so far.

The API is Paperless NGX and its documentation stipulates that if you want to transfer a new document to Paperless via API, you can “tag” it directly. If I just define one day everything works. If you have multiple tags, you should use the “tags” key multiple times. So for each day a POST field “tags” is given and an ID is specified for each.

Paperless REST API Document Upload Documentation

But Laravel always only sends the last “tags” field.

How can I change this?

$response = Http::withHeaders( [ 'Authorization' => 'Token XXXXXXX'])
            ->attach( 'document', Storage::get($filename_storage), $filename, ['Content-Type' => 'application/pdf'] )
            ->post('https://xxxxxxxxxxxxxx/api/documents/post_document/' , [
                'tags' => '123',
                            'tags' => '456'
            ]);

Unfortunately I can’t get any further.

Composer on docker: Uncaught Error: Class not found

I’m trying to build a minimal docker image to use packagist.org/packages/nikic/php-parser:

FROM php
RUN apt-get update
RUN apt-get install zip -y
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY . .

Installing the (single) dependency goes smooth (done outside Dockerfile for exposition):

root@e1aa9cdb4e13:/# composer install
< ... omitted for brevity ... >
Package operations: 1 install, 0 updates, 0 removals
  - Downloading nikic/php-parser (v5.0.2)
  - Installing nikic/php-parser (v5.0.2): Extracting archive
Generating autoload files

When I try to run the example in the docs, I crash:

root@e1aa9cdb4e13:/# php main.php
Fatal error: Uncaught Error: Class "PhpParserParserFactory" not found in /main.php:15

Here is the example I use (taken “as-is” from the docs):

<?php
use PhpParserError;
use PhpParserNodeDumper;
use PhpParserParserFactory;

$code = <<<'CODE'
<?php

function test($foo)
{
    var_dump($foo);
}
CODE;

$parser = (new ParserFactory())->createForNewestSupportedVersion();
try {
    $ast = $parser->parse($code);
} catch (Error $error) {
    echo "Parse error: {$error->getMessage()}n";
    return;
}

$dumper = new NodeDumper;
echo $dumper->dump($ast) . "n";

EDIT

Adding an explicit include from vendor directory,
I seem to get one (tiny ?) step farther:

include "/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php";

new error message:

Fatal error: Uncaught Error: Class "PhpParserPhpVersion" not found in /vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php:32

File-level DocBlock placement with namespace and declare(strict_types=1)

What is the correct placement of the file-level DocBlock when using declare(strict_types=1) and namespace?

For example is the following correct or does the DocBlock go under the opening PHP tag?

<?php
declare(strict_types=1)

/**
 * DocBlock
 */

namespace XxxXxx;

use XxxXxx;

if (!defined('ABSPATH')) {
    exit;
}

/**
 *
 */
class Xxx {
    // ...
}