Laravel Queue Job中的静态变量

时间:2017-06-18 07:24:55

标签: laravel laravel-queue

Laravel Queue作业中是否有人使用过静态变量?

我需要使用静态变量来累积传入的文件大小。

例如,如果文件总大小超过1000mb,我需要立即向远程服务器发出请求。

<payloadFactory media-type="xml">
                  <format>
                     <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
                        <soapenv:Body>
                           <ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
                        </soapenv:Body>
                     </soapenv:Envelope>
                  </format>
                  <args>
                     <arg evaluator="xml" expression="//*[local-name()='Binary']/text()"/>
                  </args>
               </payloadFactory>
               <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
               <property name="ContentType" value="application/pdf" scope="axis2" type="STRING"/>
               <property name="messageType" value="application/pdf" scope="axis2" type="STRING"/>
               <respond/>

以下是我的队列代码。

[2017-06-18 07:59:44] local.ERROR: exception 'ErrorException' with message 'serialize(): "count" returned as member variable from __sleep() but does not exist' in C:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Queue\Queue.php:89
Stack trace:
 #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'serialize(): "a...', 'C:\\xampp\\htdocs...', 89, Array)

1 个答案:

答案 0 :(得分:0)

我复制了这个问题并得到了同样的错误,然后搜索了它:https://laracasts.com/discuss/channels/laravel/using-static-variable-in-job-class

该线程断定静态变量未被序列化。

我建议您在Redis(或任何临时存储)本身中保存总文件大小,而不是执行&#34; $ count = $ count + $ this-&gt; data [&#39; file_size&#39; ];&#34;在Redis中递增计数,然后检查计数是否超出限制。

您还可以查看帖子中讨论的修复

相关问题