当所选行具有NULL值时,允许的内存大小耗尽

问题描述:

I'm trying to connect my Laravel 5.7 project to our iSeries database. My running environment is in Docker running in a Linux environment. Whenever I try to do a SELECT on a table row that contains a NULL value, I get the following error:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967320 bytes)

Replacing NULL values in the table with '' or anything else, works as expected, with all values returned correctly. The table in question only has 10 rows of data.

My Controller query code:

use App\Notification;
$notifications = Notification::where('user_id', '=', $currentUser)->orderBy('id', 'desc')->get();

My table up() Migration:

Schema::create('notifications', function (Blueprint $table) {
    $table->increments('id');
    $table->string('user_id');
    $table->string('type');
    $table->integer('severity');
    $table->text('message');
    $table->string('link')->nullable();
    $table->timestamp('read_at')->nullable();
    $table->timestamps();
    $table->softDeletes();
});

My database.php connections array:

'connections' => [
    'db2' => [
        'driver' => 'db2_ibmi_odbc',
        // or 'db2_ibmi_ibm' / 'db2_zos_odbc' / 'db2_expressc_odbc
        'driverName' => '{iSeries}',
        // or '{iSeries Access ODBC Driver}' / '{IBM i Access ODBC Driver 64-bit}' / '{IBM DB2 ODBC DRIVER}
        'host' => 'redacted',
        'username' => 'ROBERT',
        'password' => 'password',
        'database' => 'ROBERT',
        'prefix' => '',
        'schema' => 'ROBERT',
        'port' => 446,
        'date_format' => 'Y-m-d H:i:s.u',
        // or 'Y-m-d H:i:s.u' / 'Y-m-d-H.i.s.u'...
        'odbc_keywords' => [
            'SIGNON' => 3,
            'SSL' => 0,
            'CommitMode' => 2,
            'ConnectionType' => 0,
            'DefaultLibraries' => '',
            'Naming' => 0,
            'UNICODESQL' => 0,
            'DateFormat' => 5,
            'DateSeperator' => 0,
            'Decimal' => 0,
            'TimeFormat' => 0,
            'TimeSeparator' => 0,
            'TimestampFormat' => 0,
            'ConvertDateTimeToChar' => 0,
            'BLOCKFETCH' => 1,
            'BlockSizeKB' => 32,
            'AllowDataCompression' => 1,
            'CONCURRENCY' => 0,
            'LAZYCLOSE' => 0,
            'MaxFieldLength' => 15360,
            'PREFETCH' => 0,
            'QUERYTIMEOUT' => 1,
            'DefaultPkgLibrary' => 'QGPL',
            'DefaultPackage' => 'A /DEFAULT(IBM),2,0,1,0',
            'ExtendedDynamic' => 0,
            'QAQQINILibrary' => '',
            'SQDIAGCODE' => '',
            'LANGUAGEID' => 'ENU',
            'SORTTABLE' => '',
            'SortSequence' => 0,
            'SORTWEIGHT' => 0,
            'AllowUnsupportedChar' => 0,
            'CCSID' => 819,
            'GRAPHIC' => 0,
            'ForceTranslation' => 0,
            'ALLOWPROCCALLS' => 0,
            'DB2SQLSTATES' => 0,
            'DEBUG' => 0,
            'TRUEAUTOCOMMIT' => 0,
            'CATALOGOPTIONS' => 3,
            'LibraryView' => 0,
            'ODBCRemarks' => 0,
            'SEARCHPATTERN' => 1,
            'TranslationDLL' => '',
            'TranslationOption' => 0,
            'MAXTRACESIZE' => 0,
            'MultipleTraceFiles' => 1,
            'TRACE' => 0,
            'TRACEFILENAME' => '',
            'ExtendedColInfo' => 0,
        ],
        'options' => [
            PDO::ATTR_CASE => PDO::CASE_LOWER,
            PDO::ATTR_PERSISTENT => false,
            //PDO::I5_ATTR_DBC_SYS_NAMING => false,
            //PDO::I5_ATTR_COMMIT => PDO::I5_TXN_NO_COMMIT,
            //PDO::I5_ATTR_JOB_SORT => false,
            //PDO::I5_ATTR_DBC_LIBL => '',
            //PDO::I5_ATTR_DBC_CURLIB => '', 
        ]
    ],
........more, unused connections

I am using the cooperl22/laravel-db2 service provider.

My DockerFile:

FROM php:7.2-fpm-stretch

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp

ADD php/www.conf /usr/local/etc/php-fpm.d/www.conf
ADD php/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
ADD os/freetds.conf /etc/freetds/freetds.conf
ADD os/ldap.conf /etc/ldap.conf 
ADD os/main.cf /etc/postfix/main.cf
ADD iseriesaccess_7.1.0-1.0_amd64.deb /

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y postfix git libssh2-1 libssh2-1-dev telnet autoconf unixodbc-dev \
unixodbc odbcinst freetds-bin freetds-dev tdsodbc ghostscript net-tools libldap2-dev zip unzip && \
pecl install ssh2-1.1.2

RUN ln -s /usr/local/bin/php /usr/bin/php
RUN ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
RUN dpkg -i /iseriesaccess_7.1.0-1.0_amd64.deb

RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr/ && \
docker-php-ext-install pdo_odbc pdo_mysql ldap

ADD os/odbc.ini /etc/odbc.ini
ADD os/odbcinst.ini /etc/odbcinst.ini

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

CMD ["php-fpm"]

EXPOSE 5000

As you can see, I'm using the iseriesaccess_7.1.0-1.0_amd64.deb driver.

Looking at other answers, upping the php memory limit is NOT an option.

Thanks for any help.

Try increasing the value of memory_limit on your php.ini file located on /etc/php/7.2/cli/php.ini assumming you are working with PHP7.2, the path will include your php version.You can increase it until your memory requirement is fullfilled (-1 for infinite). But remember, this is not a good practice.