How to upgrade php version in aws docker

Im running an API written in PHP version 8.0.13 and while running any API calls I always see this WARNING on Cloudwatch:

- Deprecated: This installation of the SDK is using PHP version 8.0.13, which will be deprecated on January 13th, 2025.
- Please upgrade your PHP version to a minimum of 8.1.x to continue receiving updates for the AWS SDK for PHP.
- To disable this warning, set suppress_php_deprecation_warning to true on the client constructor or set the environment variable AWS_SUPPRESS_PHP_DEPRECATION_WARNING to true.
- More information can be found at: https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-php-runtimes-8-0-x-and-below-in-the-aws-sdk-for-php/
- in /opt/vendor/aws/aws-sdk-php/src/ClientResolver.php on line 1456

The AWS article:
https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-php-runtimes-8-0-x-and-below-in-the-aws-sdk-for-php/

Clearly, it says that I need to upgrade my PHP version to a minimum of 8.1.x

FROM amazon/aws-lambda-provided:al2 as builder 
ARG php_version="8.0.13"
RUN yum clean all && 
    yum install -y autoconf 
                bison 
                bzip2-devel 
                gcc 
                gcc-c++ 
                git 
                gzip 
                libcurl-devel 
                libxml2-devel 
                make 
                openssl-devel 
                tar 
                unzip 
                zip 
                openldap-devel 
                libzip010-compat 
                re2c 
                sqlite-devel 
                oniguruma 
                oniguruma-devel 
                file 
                wget 
                libldb-devel

RUN yum -y install https://archives.fedoraproject.org/pub/archive/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm 

RUN yum install -y libsodium 
                   libsodium-devel

RUN curl -sL https://github.com/php/php-src/archive/php-${php_version}.tar.gz | tar -xvz && 
    cd php-src-php-${php_version} && 
    ./buildconf --force && 
    ./configure --prefix=/opt/php-8-bin/ --with-openssl --with-curl --with-zlib --without-pear --enable-bcmath --with-bz2 --enable-mbstring --with-libdir=lib64 --with-ldap --with-mysqli && 
    make -j 5 && 
    make install && 
    /opt/php-8-bin/bin/php -v && 
    curl -sS https://getcomposer.org/installer | /opt/php-8-bin/bin/php -- --install-dir=/opt/php-8-bin/bin/ --filename=composer

COPY runtime/bootstrap /lambda-php-runtime/
RUN chmod 0755 /lambda-php-runtime/bootstrap

RUN mkdir /lambda-php-vendor && 
    cd /lambda-php-vendor && 
    /opt/php-8-bin/bin/php /opt/php-8-bin/bin/composer require guzzlehttp/guzzle && 
    /opt/php-8-bin/bin/php /opt/php-8-bin/bin/composer require aws/aws-sdk-php

RUN yum clean all && 
    rm -rf /var/cache/yum

FROM amazon/aws-lambda-provided:al2 as runtime
COPY --from=builder /opt/php-8-bin /var/lang
COPY --from=builder /lambda-php-runtime /var/runtime
COPY --from=builder /lambda-php-vendor/vendor /opt/vendor

COPY src/ /var/task/

RUN yum install -y oniguruma 
    oniguruma-devel

RUN yum clean all && 
    rm -rf /var/cache/yum

CMD [ "index" ]

The above is my current Dockerfile, How can I upgrade the version, what kind of testing needs to be done, would any functionality change?

How can I configure apache to play video file stored on local hard drive?

So sorry if this has been answered previously. I have searched for a solution without any luck. I have a Windows PC and have been using html files run from local drive using <a href=”file:/// links to various videos stored on local hard drives without any problems. When a link is selected the video will open and play in the video player (ZoomPlayer) I have installed. Only problem was any additions or deleted videos required rewriting the html code. I recently installed WAMP v3.3.5 usng php & MySql to help make the menu more automated and easier to manage. I store the video description and all the file information in a MySql database and use php to retrieve info needed to create the menu page. All working almost as intended, thanks to a lot of help I’ve received from this site. My problem I’ve run into is the file link would do nothing. Just to state that this is running only on a local lan and no ports have been opened on internet facing router. This isn’t intended to be accessed from the web.

I have setup an alias for each of the various drives in the Apache httpd.conf file. Now when a link is selected, the video downloads first to the windows temp folder then starts playing normally in Zoomplayer.
I have place AddType video/x-msvideo .avi AddType video/mp4 .mp4 AddType video/x-matroska .mkv in httpd.conf, but still have same result.

How can I avoid the download step and have it simply open in video player?

Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:xampphtdocsfetch.php

<?php

$url = 'http://www.abc.in/abc/img/';
$base = 'http://www.abc.in/';

// Pull in the external HTML contents
$contents = file_get_contents( $url );

// Use Regular Expressions to match all <img src="???" />
preg_match_all( '/<img[^>]*src=["|'](.*)["|']/Ui', $contents, $out, PREG_PATTERN_ORDER);

foreach ( $out[1] as $k=>$v ){ // Step through all SRC's

    // Prepend the URL with the $base URL (if needed)
    if ( strpos( $v, 'http://' ) !== true ) $v = $base . $v;

    // Output a link to the URL
    echo '<a href="' . $v . '">' . $v . '</a><br/>';
}



error msg

Warning: file_get_contents(http://www.abc.in/abc/img/): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:xampphtdocsfetch.php on line 9

  1. my remote server is godaddy
  2. allow_url_fopen On
  3. full control access given to directory

display list of files in a directory in a remote server

youtube dgUB1PJCVHk: Sign in to confirm you’re not a bot. This helps protect our community. Learn more

I am using norkunas/youtube-dl-php package in my Laravel application to sync youtube videos in my platform. But recently it was not sysncing videos. When i debug this i got this error
enter image description here

here is the piece of code i am using

$data =  $youtubeDL->download(
            Options::create()
                ->skipDownload(true)
                ->downloadPath(storage_path('app/temp/yt/' . $userId))
                ->output('%(id)s.json')
                ->url($channelUrl)
                ->cookies(storage_path('app/cookies.txt'))
        );

Tried to find solution but didn’t get any proper solution. I tried adding cookies as well but it still not working.

Please suggest on this thanks.

get product by attribute in woocommerce

I have products with many attributes. Attribute values can be size,color,… . I am trying to create a custom search but I can’t get the query to pull any product.

    $product_attributes = wc_get_attribute_taxonomies();
    
    $attributes = array();
    foreach ($product_attributes as $attribute) {
        $attribute_name =  $attribute->attribute_name;
        $attribute_value = isset($params[$attribute_name]) ? $params[$attribute_name] : '';
        if (!empty($attribute_value)) {
            $attributes['pa_' .$attribute_name] = $attribute_value;
           
        }
    }
    
    $ordering              = WC()->query->get_catalog_ordering_args();
    $ordering['orderby']   = array_shift(explode(' ', $ordering['orderby']));
    $ordering['orderby']   = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
    
    dump($attributes);
    $args = array(
        'status' => 'publish',
        'limit' => -1,
        'return'            => 'ids',
        'stock_status'      => 'instock',
        'visibility'        => 'visible',
        'paginate'          => true,
        'orderby'           => $ordering['orderby'],
        'order'             => 'DESC',

        'attribute' => $attributes,
    );

    $products = wc_get_products($args);

what`s the problem

Allowed memory size of 134217728 bytes exhausted into Bugsnag library

I see a few errors like this (different parts of Bugsnap):

production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) {"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) at /var/www/html/vendor/bugsnag/bugsnag/src/Report.php:683)

But I have memory_limit=3G for PHP CLI and FPM, and I don’t have ‘ini_set’ for memory_limit into PHP code.

So my question is: how I can find and fix the source of these errors?

PHPStan / @return all possible children that extend specific class

I have a problem with @return types. It seems that either it’s a bug in PHPStan or I’m doing something wrong.

Error:

abstract class Aclass {}
final class Bclass extends Aclass {}
final class Cclass extends Aclass {}

final class Factory {
    /**
     * @template T of Aclass
     * @param class-string<T> $param
     * @return T
     */
    public function create($param) {
        // some kind of factory logic
        return new Bclass();
    }
}

No error:

abstract class Aclass {}
final class Bclass extends Aclass {}
final class Cclass extends Aclass {}

final class Factory {
    /**
     * @template T of Aclass
     * @param class-string<T> $param
     * @return Aclass
     */
    public function create($param) {
        // some kind of factory logic
        return new Bclass();
    }
}

Why does PHPStan give me an error? Isn’t @template T of Aclass + @return T the same as @return Aclass?

I’m expecting no errors.

Magento 2 – Add Customer Custom Attribute to front store

I need to add a Customer custom attribute. Here is snippet of my code:

         $customerSetup->addAttribute(Customer::ENTITY, 'customer_mobile', [
            'type' => 'varchar',
            'label' => 'Customer Mobile',
            'input' => 'text',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 85,
            'position' => 999,
            'system' => 0,
            'visible_on_front' => true
        ]);

        $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'customer_mobile')
            ->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer', 'customer_account_edit'],
            ]);

        $attribute->save();

It successfully adds ‘customer_mobile’ in the admin. But it does not show on the front store, in edit user form. I check on the table customer_form_attribute and there are 2 rows with my new custom attribute with 2 forms. Do I need to override the customer_account_edit.xml to display? I try to work on this for 2 days, but no hope. Can anyone help me.

Thank you very much!

procedure of filling gloabl $wp_the_query

I wanna know how
do_action( ‘template_redirect’ ); is filling up [queried_object] => WP_Term Object
(
[term_id] => 43
[name] => media
[slug] => media
[term_group] => 0
[term_taxonomy_id] => 42
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 0
[filter] => raw
[cat_ID] => 43
[category_count] => 0
[category_description] =>
[cat_name] => media
[category_nicename] => media
[category_parent] => 0
) in global $wp_the_query

if ( wp_using_themes() ) {
    /**
     * Fires before determining which template to load.
     *
     * @since 1.5.0
     */
    echo "checking global before in template_redirect";
global $wp_the_query;
print_r($wp_the_query);
echo "checking global before in template_redirect";


    do_action( 'template_redirect' );

    echo "checking global after template_redirect ";
    print_r($wp_the_query);
    echo "checking global after template_redirect ";
}

I printed the query one before and one after the do_action( ‘template_redirect’ );. removing do_action( ‘template_redirect’ ); empties $wp_the_query->queried_object

php server code generated by swagger codegen is too big

I used codegen of Swagger to generate php server code based on openAPI document. The interface is simple and not that much complex. However, the generated code has in total (after downloading all needed dependencies using composer) a size of 1.7 GB.

Is this possible and realistic? This is bigger than the size of a complete OS! Does someone have an explanation?

I understand that adding abstraction layers inbetween results in increasing the size, but anyhow 1.7 GB for a simple REST server is unbelievable and really HUGE.

Adding a custom login field to WordPress to use it as authenticate

I have added a function to my WordPress site to modify the login page by including a custom field. This field is intended to require users to enter a specific value in addition to their username and password. However, the custom field is not functioning as expected.

When users submit the login form, they can input any value in the custom field, and the login process does not validate this input against the expected value stored in the option portal_access_code. As a result, users can log in as long as they provide a valid username and password, regardless of the value they enter in the security code field.

I have checked the implementation using error_log and confirmed that it logs both the actual value of the option set ('portal_access_code') and the value entered by the user. However, the login process allows users to authenticate without validating the custom field, bypassing the intended check. It’s as if the login mechanism is running before the custom validation takes place, so users can log in without error, even if their input does not match the expected value. I think this happens after WordPress has already authenticated the user based on the username and password.

When any user trying to login, this code log both codes (code that stored in database, and code that user entered) on error_log file:

[31-Aug-2024 08:13:05 UTC] Portal Access Code: NTM-81641992@BRHPUL-nu581p
[31-Aug-2024 08:13:05 UTC] Submitted Security Code: 1234

So the actual code in the database is NTM-81641992@BRHPUL-nu581p (it’s generating automatically with another function) but users can bypass it by entering any value into the login field!

<?php

// Add the security code field to the login form
add_action('login_form', 'add_security_code_field_ntm');
function add_security_code_field_ntm() {
    echo '<p>
            <label for="security_code">'.__('Security Code').'<br />
            <input type="text" name="security_code" id="security_code" class="input" value="" size="100" required /></label> <!-- Added required attribute -->
          </p>
          <script>
            document.getElementById("loginform").onsubmit = function() {
                var securityCode = document.getElementById("security_code").value;
                if (securityCode === "") {
                    alert("Please enter the Security Code field"); // Alert message for the empty field
                    return false; // Prevent form submission
                }
                return true; // Allow form submission
            }
          </script>';
}

// Validate the security code
add_filter('authenticate', 'validate_security_code_ntm', 30, 3);
function validate_security_code_ntm($user, $username, $password) {
    // Check if the login form was submitted with a security code
    if (isset($_POST['security_code'])) {
        $portal_access_code = get_option('portal_access_code', 'error_code');
        $security_code = sanitize_text_field($_POST['security_code']);

        error_log("Portal Access Code: " . $portal_access_code);
        error_log("Submitted Security Code: " . $security_code);

        // Compare with the stored access code
        if (empty($security_code)) {
            return new WP_Error('empty_security_code', __('Please Enter the Security Code.'));
        }
        if ($security_code !== $portal_access_code) {
            return new WP_Error('invalid_security_code', __('Security Code is not correct!'));
        }
    }
    return $user; // Return the user object if there are no errors
}

// Restrict login methods except wp-login.php
add_action('init', 'restrict_login_methods_ntm');
function restrict_login_methods_ntm() {
    if (is_user_logged_in() || !isset($_REQUEST['log'])) {
        return;
    }
    $request_uri = $_SERVER['REQUEST_URI'];
    if (!preg_match('/wp-login.php/', $request_uri)) {
        wp_die('You should use normal way to login to admin panel!');
    }
    add_filter('xmlrpc_enabled', '__return_false');
}

i want to merge two laravel projects into one project [closed]

I have two Laravel projects, each with its own repository:

sresth.com – This project serves the user-facing part of the website.
sresthadmin.com – This project serves the admin panel.
I want to merge these two projects into a single Laravel project with the following structure:

The user-facing part should remain accessible via sresth.com.
The admin panel should be accessible via sresth.com/admin.
Both projects are currently in separate repositories. I’m looking for the best approach to merge them into one project and one repository without losing any functionality or data. How can I achieve this?

Here are a few specific concerns:

How should I structure the directories and routes for the admin panel within the merged project?
How do I handle merging the environment configuration files (.env)?
What’s the best way to manage potential conflicts, such as overlapping routes, models, or migrations?
Any advice or step-by-step guidance would be greatly appreciated!

PHP and Java functions returning different dates when calculating 6 months ahead

I have the following code to calculate what day it will be in 6 months from today.

// Java code
Date currentDate = (new SimpleDateFormat("yyyy-MM-dd")).parse("2024-08-30");
        
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.add(Calendar.MONTH, 6);
Date sixMonthsLaterDate = calendar.getTime();
String sixMonthsLaterDateString = new SimpleDateFormat("yyyy-MM-dd").format(sixMonthsLaterDate);

System.out.println("sixMonthsLaterDateString: " + sixMonthsLaterDateString); // returns 2025-02-28

in Java, it returns “2025-02-28”

// PHP code
$currentDate = date_create_from_format('Y-m-d', '2024-08-30');
$sixMonthsLaterDate = $currentDate->modify('+6 month');
$sixMonthsLaterDateString = date_format($sixMonthsLaterDate, 'Y-m-d');
echo "sixMonthsLaterDateString: $sixMonthsLaterDateString"; // returns 2025-03-02

in PHP, it returns “2025-03-02”

Why are they different? Can anyone explain it? Thanks!