Strange behaviour with file_get_contents/file_put_contents

Wanted to write a quick one liner to count page loads, not worrying about users, sessions or refreshes, and tried this:

file_put_contents(“page.test”, ((file_get_contents(“page.test”))+1));

echo “Test:”.file_get_contents(“page.test”);

On every load or refresh, the page.test file increases by 3, not 1 which I expected. If I write each step as a separate line of code and use a counter variable as an intermediate step, then it all works as expected, but the one liner goes up 3 at a time.

Appreciate some wisdom from the experts! Thank you. Ray

PHPMailer, can’t send svg img with and without attachement

My Mail is defined like that

        $this->mail = new PHPMailer();
        $this->mail->IsSMTP();
        $this->mail->CharSet    = 'UTF-8';
        $this->mail->Host       = '';
        $this->mail->SMTPAuth   = true;
        $this->mail->Port       = 465;
        $this->mail->SMTPSecure = 'ssl';
        $this->mail->Username   = '';
        $this->mail->Password   = '';
        $this->mail->From       = '';
        $this->mail->FromName   = '';
        $this->mail->WordWrap   = 78;
        switch( is_array( $address ) )
        {
            case false: $this->mail->addAddress( $address ); break;
            case true : foreach( $address as $addr ) { $this->mail->addAddress( $addr ); } break;
        }
        $this->mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT']."/image/icon/logo-f39200.svg", "logo-f39200", 'logo-f39200.svg' );
        $this->mail->IsHTML(true);
        $this->mail->Body    = $msg;
        $this->mail->Subject = $subject;

And I want to put an svg image inside it but It don’t work, here’s my body :

$message  = '
    <html>
        <head>
            <title>
                Lorem lorem
            </title>
        </head>
        <body>
            <div style="height:300px;border:1px solid red;display:flex; flex-direction:column; justify-content:flex-start; align-items:center"> //The style tag was here for test
                <h2>Lorem</h2>
                <div>
                    <p>
                       Lorem lorem lorem lorem
                    </p>
                </div>
                <img src="cid:logo-f39200" alt="logo"/>
            </div>    
        </body>
    </html>';

I try with :

  • src=”cid:logo” + addEmbeddedImage //I got the attachment but no image in the body of the mail
  • src=”absolute path” + addEmbeddedImage //I got the attachment but no image
  • src=”aboslute path” //I got nothing
  • addEmbeddedImage //I got the attachement only

Don’t know what I miss, thanks in advance

Persisting Log entity using another EntityManager

I have second connection and entity manager configured for logging only. It works fine in my logging service, but there is a problem with:

$user = $this->security->getUser();
$log->setUser($user);

When trying this I’ve got “A new entity was found through the relationship” exception. And it’s ok, because second entity manager doesn’t know about User and is trying to cascade persist object (which is not configured). In previous version of Symfony (3.x I guess) I used this workaround (from my previous version of code):

$user = $token->getUser();
$userManaged = $em->getRepository('AppBundle:User')->find($user->getId());
$log->setUser($userManaged);

It worked, but now (Symfony 6.0.7) it no longer works. I’m trying now:

    $user = $this->security->getUser();
    if($user){
        $userManaged = $em->getRepository('App:User')->find($user->getId());
        $log->setUser($userManaged);            
    }

And still having “A new entity was found through the relationship”.

How should I do this in proper way? Here is my doctrine.yml ORM section:

orm:
    auto_generate_proxy_classes: true
    default_entity_manager: default
    entity_managers:
        default:
            connection: default                
            naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            auto_mapping: true
            mappings:
                App: ~
                    is_bundle: false
                    dir: '%kernel.project_dir%/src/Entity'
                    prefix: 'AppEntity'
                    alias: App
        log:
            connection: log
            naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            mappings:
                App:
                    is_bundle: false
                    dir: '%kernel.project_dir%/src/Entity'
                    prefix: 'AppEntity'
                    alias: App

Laravel – Grabbing multiple CarbonPeriod and then continue a while loop with it

So I have this code:

$companyHolidays = Holiday::all();
$newholiday = [];
foreach($companyHolidays as $holiday){
    $newholiday[] = [
        'id' => $holiday->id,
        'title' => $holiday->title,
        'start' => $holiday->start,
        'end' => $holiday->end,
        'parsed_company_holidays' => CarbonPeriod::create($holiday->start, $holiday->end)
    ];
}


$customHoliday = [];
foreach ($newholiday as $holiday) {
   $customHoliday[] = $holiday['parsed_company_holidays']->toArray();
}


   while ($i < $eventRepeats) {

        // add one week
        $eventStart->addDays(7);


        if (in_array($eventStart->translatedFormat('Y-m-d'), $holidaysArray)) {
            continue;
        }

        // todo: this here is the issue
        if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
            continue;
        }


        echo '<div class="text-primary font-normal mt-6 mb-2">'.$count++.'. Termin</div>';
        echo '<div class="bg-dark-gray rounded-lg border-l-4">';
        echo '<div class="p-3">';
        echo $eventStart->translatedFormat('l, d. F Y, H:i');
        echo ' - ';
        echo $eventEnd->translatedFormat('H:i');
        echo '</div></div>';

        // increase iteration
        $i++;

    }

if I do dd($customHoliday); I get the following:

enter image description here

Inside it are these:

enter image description here

So for comparing the dates inside the if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {

it would probably look like the $holidaysArray:

enter image description here

But I cannot figur out how to merge all the arrays and then make the dates inside the $customHoliday comparable like the $holidaysArray (based on YASUMI API)

because I already implemented the holiday API and it continue the loop, if in the array:

if (in_array($eventStart->translatedFormat('Y-m-d'), $holidaysArray)) {
    continue;
}

but with the current way it does not work with this:

if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
    continue;
}

Finding differences in json in Laravel

I am beginner in Laravel.
I make my application in Laravel 8,

I have this value in DB:

$json = {
    "old": {
        "id": 1, 
        "hash": "19f149b6-f7e2-4d61-b3c5-d46ebc92f681", 
        "car_id": 2, 
        "comments": "uwagi", 
        "driver_id": 1, 
        "address_to": "adres dostawy", 
        "carrier_id": 22, 
        "company_id": 1, 
        "created_at": "2022-04-14T09:07:41.000000Z", 
        "data_start": "2022-04-01", 
        "deleted_at": null, 
        "updated_at": "2022-04-14T09:07:41.000000Z", 
        "carrier_nip": "728-597-9477", 
        "data_finish": "2022-04-04", 
        "address_from": "adres wyjazdu", 
        "carrier_city": "Lake Emersonville", 
        "carrier_name": "Satterfield, Lebsack and O'Conner", 
        "order_number": "Numer zlecenia", 
        "speed_number": "Numer zlecenia speed - spedycja", 
        "carrier_email": "[email protected]", 
        "carrier_phone": "347.731.2768 x1508", 
        "dispatcher_id": 3, 
        "carrier_street": "6342 Pollich Crossroad", 
        "selected_files": "[7,8,9]", 
        "transport_type": 2, 
        "deliver_comments": null, 
        "transport_status": 3, 
        "is_neutral_option": 2,
        "selected_products": "[1,3]", 
        "transport_content": "kontakt", 
        "delivery_signature": null, 
        "selected_documents": "[5]", 
        "carrier_postal_code": "36804-7962", 
        "hidden_carrier_data": 0, 
        "delivery_name_surname": null, 
        "delivery_signature_binary": null, 
        "disable_change_status_driver": 0
    }, 
    "attributes": {
        "id": 1, 
        "hash": "19f149b6-f7e2-4d61-b3c5-d46ebc92f681", 
        "car_id": 2, 
        "comments": "uwagi", 
        "driver_id": 1, 
        "address_to": 
        "adres dostawy", 
        "carrier_id": 22, 
        "company_id": 1, 
        "created_at": "2022-04-14T09:07:41.000000Z", 
        "data_start": "2022-04-01", 
        "deleted_at": null, 
        "updated_at": "2022-04-14T09:09:08.000000Z", 
        "carrier_nip": "728-597-9477", 
        "data_finish": "2022-04-04", 
        "address_from": "adres wyjazdu", 
        "carrier_city": "Lake Emersonville", 
        "carrier_name": "Satterfield, Lebsack and O'Conner", 
        "order_number": "Numer zlecenia", 
        "speed_number": "Numer zlecenia speed - spedycja", 
        "carrier_email": "[email protected]", 
        "carrier_phone": "347.731.2768 x1508", 
        "dispatcher_id": 4, 
        "carrier_street": "6342 Pollich Crossroad", 
        "selected_files": "[7,8,9]", 
        "transport_type": 2, 
        "deliver_comments": null, 
        "transport_status": 3, 
        "is_neutral_option": 2, 
        "selected_products": "[1,3,2]", 
        "transport_content": "kontakt", 
        "delivery_signature": null, 
        "selected_documents": "[5,6,4]", 
        "carrier_postal_code": "36804-7962", 
        "hidden_carrier_data": 0, 
        "delivery_name_surname": null, 
        "delivery_signature_binary": null, 
        "disable_change_status_driver": 0
        }
    }

I need show differences from OLD and Attributes.
How can I make it?

Please help me.

multidimensional array remove item from child array

i have a problem with my multidimensional array. I want to remove some items from child array by $id value.

here is my multidimensional example array and selectedIds:

$myArray = [
    ['id' => '2', 
    'name' => 'Punk'
    ],[
    'id' => '5', 
    'name' => 'Rock', 
    'children' => [
        '30' => ['id' => '30', 
                'name' => 'Hard Rock', 
                'parentId' => '5'
                ], 
        '40' => ['id' => '40', 
                'name' => 'Soft Rock', 
                'parentId' => '5'
                ],  
        '50' => ['id' => '50', 
                'name' => 'Glam Rock', 
                'parentId' => '5'
                ]
        ]
    ]
];

$selectedIds = [2,5,30];

and i want to remove from array those items which are not in selectedIds array.

so i want to have output:

$outputArray = [
    [
    'id' => '2', 
    'name' => 'Punk'
    ],[
    'id' => '5', 
    'name' => 'Rock', 
    'children' => [
            '30' => ['id' => '30', 
                    'name' => 'Hard Rock', 
                    'parentId' => '5']
                ]
    ]
];

i try to make it with foreach and array_key_exist but its not correct:

foreach ($myArray as $key=>$value) {
    if (array_key_exists('children', $value)) {
        foreach ($selectedIds as $id) {
            if (isset($value['children'][$id])) {
                $outputArray[] = $value['children'][$id];
            }
        }
    }
}
print_r($outputArray);

this outpus is only item with id 30

How to fix Fatal error in Ratchet Websocket?

When I run my server.php file, it gives me the following error on cmd:
PHP Fatal error: Uncaught RuntimeException: Failed to listen on "tcp://0.0.0.0:8080": An attempt was made to access a socket in a way forbidden by its access permissions. (EACCES) in C:xampphtdocsvchatvendorreactsocketsrcTcpServer.php:184

is there any way to fix it?

Translate c# Http request into php CURL, what is “request.AddParameter” of c# in php?

I’ve a c# sample script as following:

/* Step One: Call /auth/token for client Authentication and to obtain an Access Token */
/* Replace siteDomainName with the corresponding domain URL*/
var client = new RestClient("{siteDomainName}/auth/token");
client.Timeout = -1;

string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes({applicationId} + ":" + {sharedSecret}));
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic " + svcCredentials);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{ "RefreshToken": {refeshToken} }",ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
var tokenResponse = JsonConvert.DeserializeObject( response.Content);

/* Step Two: Call Product API /v1/product/{productCode} using the Access Token obtained for API Authorization */
client = new RestClient("{siteDomainName}/v1/product/{productCode}");
client.Timeout = -1;

var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer {tokenResponse.Token}");
request.AddParameter("text/plain", "",  ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

I don’t understand how to translate this line request.AddParameter("application/json", "{ "RefreshToken": {refeshToken} }",ParameterType.RequestBody);

here is the php so far i tried

<?php
$app_id = "20dd14a2d3cfsdf4eb1234756b26b";
$shared_secret = "d561e8sdf8ca0b914f452201ad523";
$refresh_token = "39fe926b233dfb130ca0f69e8356c";
$svcCredentials = base64_encode($app_id .":". $shared_secret);

$url = "https://example.com.au";

$ch = curl_init($url . "/auth/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "application/json");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ RefreshToken: {39fe926b96sdfb130ca0f69e8356c} }');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    "Authorization: Basic $svcCredentials",
                    "Content-Type: application/json"
                ));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);
var_dump($token);

PHP – An unidentified value inside array suddenly appear after unset()?

What Im trying to do is I want to delete specific array index value inside this array that Im comparing it with another array. I heard unset is the way to go so I give it a try. Below is the json encode before the unset().

[
 {
  "crs_id": "1269",
  "crs_code": "UI3/212",
  "crs_title_bm": "LOL",
  "crs_title_bi": "OLO",
  "crs_description_bm": "ye ah tu",
  "crs_description_bi": "righttt",
  "crs_edit_by": "991018222222",
  "crs_edit_date": "2022-04-11 05:43:30",
  "crs_aprv_type1": "0",
  "crs_aprv_val1": null,
  "crs_aprv_type2": "0",
  "crs_aprv_val2": null,
  "crs_aprv_type3": "0",
  "crs_aprv_val3": null,
  "crs_aprv_type4": "0",
  "crs_aprv_val4": null,
  "crs_aprv_type5": "0",
  "crs_aprv_val5": null,
  "crs_indakua": "1",
  "crs_indpengembangan": "0",
  "crs_status": "1",
  "cat_id": "27",
  "typ_id": "7",
  "clssfctn_id": "8",
  "crs_grp_id": "8",
  "crs_org_id": "16",
  "cdept_id": "40408000017"
 },
 {
  "crs_id": "1270",
  "crs_code": "ABC18",
  "crs_title_bm": "LOL2",
  "crs_title_bi": "OLO2",
  "crs_description_bm": "yow",
  "crs_description_bi": "right",
  "crs_edit_by": "991018222222",
  "crs_edit_date": "2022-04-11 05:42:52",
  "crs_aprv_type1": "0",
  "crs_aprv_val1": null,
  "crs_aprv_type2": "0",
  "crs_aprv_val2": null,
  "crs_aprv_type3": "0",
  "crs_aprv_val3": null,
  "crs_aprv_type4": "0",
  "crs_aprv_val4": null,
  "crs_aprv_type5": "0",
  "crs_aprv_val5": null,
  "crs_indakua": "1",
  "crs_indpengembangan": "0",
  "crs_status": "1",
  "cat_id": "27",
  "typ_id": "7",
  "clssfctn_id": "4",
  "crs_grp_id": "9",
  "crs_org_id": "11",
  "cdept_id": "40405000000"
 },
 {
  "crs_id": "1271",
  "crs_code": "TIME12",
  "crs_title_bm": "CHECK",
  "crs_title_bi": "CHECK",
  "crs_description_bm": "nk check it is mase",
  "crs_description_bi": "nk check it is mase",
  "crs_edit_by": "991018222222",
  "crs_edit_date": "2022-04-11 05:41:54",
  "crs_aprv_type1": "0",
  "crs_aprv_val1": null,
  "crs_aprv_type2": "0",
  "crs_aprv_val2": null,
  "crs_aprv_type3": "0",
  "crs_aprv_val3": null,
  "crs_aprv_type4": "0",
  "crs_aprv_val4": null,
  "crs_aprv_type5": "0",
  "crs_aprv_val5": null,
  "crs_indakua": "1",
  "crs_indpengembangan": "0",
  "crs_status": "1",
  "cat_id": "27",
  "typ_id": "4",
  "clssfctn_id": "4",
  "crs_grp_id": "3",
  "crs_org_id": "18",
  "cdept_id": "40408000034"
 }
]

It is exactly what I hope to see so nothing wrong here. Below is the json encode after the unset().

{
 "1": {
       "crs_id": "1270",
       "crs_code": "ABC18",
       "crs_title_bm": "LOL2",
       "crs_title_bi": "OLO2",
       "crs_description_bm": "yow",
       "crs_description_bi": "right",
       "crs_edit_by": "991018222222",
       "crs_edit_date": "2022-04-11 05:42:52",
       "crs_aprv_type1": "0",
       "crs_aprv_val1": null,
       "crs_aprv_type2": "0",
       "crs_aprv_val2": null,
       "crs_aprv_type3": "0",
       "crs_aprv_val3": null,
       "crs_aprv_type4": "0",
       "crs_aprv_val4": null,
       "crs_aprv_type5": "0",
       "crs_aprv_val5": null,
       "crs_indakua": "1",
       "crs_indpengembangan": "0",
       "crs_status": "1",
       "cat_id": "27",
       "typ_id": "7",
       "clssfctn_id": "4",
       "crs_grp_id": "9",
       "crs_org_id": "11",
       "cdept_id": "40405000000"
      }
 }

The above json encode is still what I hope to see, it show the correct array key index to be shown but what make it a problem for me is the value "1" suddenly appear and I noticed it no longer in an array form(?) since before unset it shown [.....] but after unset it shown {....}

What I want to see is the "1" is gone and instead of {....} I want it to be [.....]

How to compare key’s value and get value in PHP array

I have an array like this

Array
(
    [10] => 0
    [30] => 2
    [90] => 5
    [365] => 10

)

Array Key have #days and value have #percentage.

Now if pass day value between 0 to 10 days then percentage will be 0, if between 11 to 30 days then percentage will be 2 if between 31 to 90 days then percentage will be 5
if 500 days then 10

My code is

    $closest = null;
    foreach ($stake as $k=>$v) {
        echo "abs($search - $closest)";
        echo "abs($k - $search)";
        if ($closest === null || abs($search - $closest) > abs($k - $search)) {
          $closest = $k;
       }
    }

but when i pass 11 it’s return 10 instead of 30

WordPress – Load more posts with AJAX & exclude posts

I made a “load more” button to my website, following this awesome tutorial.
Everything works fine, but in the homepage i have 3 different loops (1 sticky post, 3 evidence) and the load more starts from post #5.

In the main loops, I have excluded the already-showed posts with the IDs and “post__not_in” and everything works fine.

The problem is when I call the load more, the loop starts from post 1. If I set to start from page 2 I have a duplicate post (that’s because I have to load post in multiple of 3).

I’have tried to get the IDs list in my loadmore file with GLOBALS, but it seems not working 🙁

How can I pass my main loop variable to the load more query?

This is my main loop:

<?php
$myquery = new WP_Query([
    'post_type'      => 'post',
  'posts_per_page' => 3,
  'post_status'    => 'publish',
'orderby' => 'date',
'order'   => 'DESC',
    'post__not_in' => $ids
]); if($myquery->have_posts()): ?>

<div class="articles-container append-posts">
    <?php
    while($myquery->have_posts()) : $myquery->the_post();
$ids[] = get_the_ID(); ?>

<?php get_template_part( 'template-parts/loop', 'posts' ); ?>

<?php endwhile; ?>
</div>

This is the load-more file:

function misha_loadmore_ajax_handler(){

// prepare our arguments for the query
$args = json_decode( stripslashes( $_POST['query'] ), true );
$args['paged'] = $_POST['page'] + 1; // we need next page to be loaded
$args['post_status'] = 'publish';
$args['post_type'] = 'post';
$args['post_per_page'] = 3;
$args['orderby'] = 'date';
$args['order'] = 'DESC';

// it is always better to use WP_Query but not here
query_posts( $args );

if( have_posts() ) :

    // run the loop
    while( have_posts() ): the_post();

        // look into your theme code how the posts are inserted, but you can use your own HTML of course
        // do you remember? - my example is adapted for Twenty Seventeen theme
        get_template_part( 'template-parts/loop', 'posts' );
        // for the test purposes comment the line above and uncomment the below one
        // the_title();


    endwhile;

endif;
die; // here we exit the script and even no wp_reset_query() required! }

WordPress update theme after install in PHP loop (Theme_Upgrader)

I’m working on a plugin that will automatically download a theme from a list, then update, and activate it.

Considering there are a number of potential errors (i.e. improper PHP version, etc), I’m trying to make it re-try after encountering an error.

The problem is that if the first theme fails (in this case, because of a PHP error – requires 7.2, I am testing with 7.0), WordPress will not perform the update on the second theme (retrogeek.0.4.zip).

However, if I make retrogeek.0.4.zip the first theme in the list, WordPress will automatically update the theme. This appears to be some sort of caching issue, but I’ve been trying for 3+ hours now and cannot get it to work.

I’ve tried a ton of variations of wp_clean_themes_cache(false) and anything else I can find. There really isn’t much documentation on this sort of thing.

I’ve also tried:

  • Nulling $test_theme_installer at the end of the loop
  • Making $test_theme_install->upgrade a variable and nulling it
  • Using “bulk_upgrade” outside of the loop

Here is the code I have now:

require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
require_once(ABSPATH . 'wp-admin/includes/class-theme-upgrader.php');

$grab_theme_url = array(
        'https://downloads.wordpress.org/theme/sirat.0.8.8.zip',
        'https://downloads.wordpress.org/theme/retrogeek.0.4.zip',
);

for($i=0; $i < 3; $i++) {

 $grab_theme_url = $grab_theme_url[$i];
 $theme_folder_path = ABSPATH . "wp-content/themes/";
 $theme_zip_file = basename(parse_url($grab_theme_url, PHP_URL_PATH));

 copy($grab_theme_url, $theme_folder_path . $theme_zip_file);

 $theme_file_unzipped = preg_replace('/.(.*)/','',$theme_zip_file);

 // ----------------------------------------------------------------------------------------
 //  Install and update the theme
 // ----------------------------------------------------------------------------------------
 $args = array('clear_update_cache' => false);

 $test_theme_install = new Theme_Upgrader();
 $test_theme_installer = $test_theme_install->install($theme_folder_path . $theme_zip_file, $args);

 if($test_theme_installer !== null) {
     $test_theme_install->upgrade($theme_file_unzipped, $args);
     break;
 }
     echo "Theme incompatible... trying again.";
     unlink($theme_folder_path . $theme_zip_file);

}

php-fpm request hangs after producing output and PHP finishes

Instana trace of the problem:
Instana trace showing the problem

The problem: randomly, some requests take an extra 20 to 60s to finish compared to normal.

Manually running CURL shows the following behaviour:

  • curl example.com/api
  • 2 seconds – no output nothing happens (I expect this to be PHP processing time)
  • 0.5-1 seconds – lots of JSON output and then it suddenly stops randomly, like in the middle div class="aa
  • 20+ seconds – no output
  • the last second – the remaining 1-2 lines of the request output are displayed
  • request finishes

I expect to not have the 20+ seconds delay where nothing happens.

Captured tcpdump of the communication

Infrastructure

tcpdump of the nginx <-> php-from communication

To note that the lat FCGI_STDOUT packet is delayed by 50+ seconds, and it contains a few bytes(in this case the json closing tags “]}}” ):

FastCGI (FCGI_STDOUT)
Version: 1
Type: FCGI_STDOUT (6)
Request ID: 1
Content Length: 6
Padding Length: 2
Content Data: 5c6e225d5d7d
Padding Data: 0000

FastCGI (FCGI_STDOUT)
Version: 1
Type: FCGI_STDOUT (6)
Request ID: 1
Content Length: 6
Padding Length: 2
Content Data: 5c6e225d5d7d
Padding Data: 0000

My php-fpm settings:

# php-fpm -v
PHP 7.4.28 (fpm-fcgi) (built: Mar 29 2022 03:26:54)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies


[www]
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen = 0.0.0.0:9000
listen.backlog = 1024
process.priority = 0
pm = dynamic
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.process_idle_timeout = 55
pm.max_children = 100
pm.start_servers = 10
pm.max_requests = 10000
slowlog = /var/log/php-fpm/slowlog.log
request_slowlog_timeout = 10
request_terminate_timeout = 600
user = www-data
catch_workers_output = yes
security.limit_extensions = .php .phar
pm.status_path = /status
php_admin_value[memory_limit] = 512M
php_admin_value[post_max_size] = 256M
php_admin_value[upload_max_filesize] = 256M
php_admin_value[max_execution_time] = 60
php_admin_value[opcache.revalidate_freq] = 0
php_admin_value[opcache.validate_timestamps] = 0
php_admin_value[opcache.max_accelerated_files] = 32531
php_admin_value[opcache.memory_consumption] = 512M
php_admin_value[opcache.interned_strings_buffer] = 128
php_admin_value[opcache.huge_code_pages] = 0
php_admin_value[zend.assertions] = 0
php_admin_value[max_input_vars] = 2000

My nginx settings:

# nginx -v
nginx version: nginx/1.20.1


upstream php {
server 127.0.0.1:9000;
}

server_tokens off;
server_names_hash_bucket_size 256;
client_max_body_size 256m;

server {
listen 80;
server_name xxx;

root /usr/share/xxx/public_api;
index index.php;
try_files $uri $uri/ /index.php?$args;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

client_header_timeout 120;
client_body_timeout 120;
send_timeout 120;
keepalive_timeout 60;

gzip on;
gzip_comp_level 4;
gzip_proxied any;
gzip_types application/atom+xml application/javascript application/json application/rss+xml
application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json
application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css
text/plain text/x-component;

location ~ .php$ {
fastcgi_connect_timeout 60s;
fastcgi_read_timeout 120s;
fastcgi_send_timeout 120s;

fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

fastcgi_param APPLICATION_ENV live;
fastcgi_param HTTPS off;

opentracing_fastcgi_propagate_context;
}
}

Combine array values with specific key has same value

I have the following array:

[
    {
       amendment: 1,
       lcnumber: "A1114564564CT",
       31D: "New Note"
    },
   {
      27: "0/0 (Number)(Total)",
      amendment: 1,
      lcnumber: "A1114564564CT",
   },
   {
      amendment: 2,
      lcnumber: "A1114564564CT",
      31D: "IN SINGAPORE (120 Days from L/C issue date)",
      32B: "USD"
   },
   {
     27: "2/2 (Number)(Total)",
     amendment: 2,
     lcnumber: "A1114564564CT",
     39B: "Exceeding"
   }
  ]

What I’m trying to do, is to combine the values into one index with the same amendment count

This is my expected output

 [
    {
       amendment: 1,
       lcnumber: "A1114564564CT",
       31D: "New Note",
       27: "0/0 (Number)(Total)",
    },
   {
      amendment: 2,
      lcnumber: "A1114564564CT",
      31D: "IN SINGAPORE (120 Days from L/C issue date)",
      32B: "USD",
      27: "2/2 (Number)(Total)",
      39B: "Exceeding"
   },
  ]

I’ve tried writing a foreach loop but this didn’t work

foreach($final_datas as $arrflight) {
    $final_array[] = (object) array(
        'lcnumber' => 'AZ300',
        $arrflight['swift_code'] => $arrflight['note']
    ); 
}

code for searching the query in such a way that it should search the keyword from both table1 &2 in which the table 1

I have a database which has 2 tables in table1 there is data of around 5000 rows and in this cid is the primary key and in table2 there are the alternate names of the names which is in table1.

now what I want to do is whenever someone searches a keyword it should go and check both the tables and then display the only when they have the same cid. and the table2 has many entries and though the cid is in repetition.

can someone give me a suitable solution for the same.I really need the help and that too urgent..