最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PHP exec() resulting in infiniteforever loop when calling another PHP script - Stack Overflow

programmeradmin5浏览0评论

I need to use exec() in my PHP script to call another (long-running) PHP script.

I am currently trying to create a couple of simple test scripts, but I end up with an infinite loop.

test.php is my initial script and simple.php is the script that it calls via exec().

simple.php:

<?php
error_log('simple.php called.');
echo 'OK';

simple.php works fine if I go into Terminal and execute:

php tasks/simple.php

But when I try and call it via exec() in test.php, I end up with an infinite loop. The code shows the commands I've tried, along with the result for each one.

test.php:

<?php

error_log('test.php called'); // Test code to check infinite loop

$cmd = 'dir'; // This works!

//$cmd = 'php tasks/simple.php'; // Loops forever

//$cmd = 'php tasks/simple.php >/dev/null &'; // With this, the browser doesn't get stuck in an infinite loop, but simple.php is called thousands of times

//$cmd = 'php tasks/this-script-does-not-exist.php';// Loops forever

//$cmd = "php /home/public_html/my_test/tasks/simple.php"; // Loops forever

//$cmd = 'php /home/public_html/my_test/tasks/simple.php'; // Loops forever

//$cmd = 'php-cli tasks/simple.php'; // $return_val: 127. $output:
/*
Array
(
)
*/

//$cmd = "php-cli /home/public_html/my_test/tasks/simple.php"; // $return_val: 0. $output:
/*
Array
(
    [0] => X-Powered-By: PHP/8.1.31
    [1] => Content-Encoding: gzip
    [2] => Vary: Accept-Encoding
    [3] => Content-type: text/html; charset=UTF-8
    [4] => 
    [5] => �UWuP\ק㡻a����n�c�٥�xĥ��nYB��nD@��W�]`��}��o��ǝ3w~'��~@E 80���%���'��]��`�@�,@9 �)���=6"vE����o00�*�*0�2z,-�DX����_����R�q�u��q���y��!D�",��˭����?�@�����e``��;��K������4���8��r��i��DX��e��ui�rB
    [6] => ���4!鷁3��J�Y���?�5��L�](.R�]E��VBO�_�}^���\�{f�ȼ��Ez�N:��7����fU�w�6
�NK�r��:�]�~������R�Qc}V=<�hdj�l�.:������۷��e{`�NK'�P#�p7�'y��m#B*k*��T��׏�:±&o�^��X}�v����KO�dt� ������mߤo��ĸ��3\��b�_p���    H��Et6�&`���{�H�\ޜ�C
��'\�$�X�������M��NZ;��m��6���e�M�{��8�l����+��۸�t�7�ڗ��mu��AN0��u-�1}�l��sn�Oe)��c��(h���z""r��t���c!4���E����ϗ+�e�Ԧ飓C��Թ��ɊW�˖�F�^�+��n?=E�fz\��B��ȟ�x����D뀢:��Xc@xʱ��Qñw�0,�+uP5��7~�����?��F��x��&�?8�O3�(�e�\�\eE����.T1)Cm�A��5�%w�#�7�ɴ�(�'^¥�r�����@��*��e��B��G2����r�K$��٘A����Bvd��2���N��_YD�X���L����TՅ��9_��Z�_?o���B��ќ]�M㐖(���P]�P#;ԃlbd�Q�����"k   ��(�cs��k�A"E]��N��_M<�5�u;��,�z ������,����0%�\�����-�e?Dj����>u���o�   f5��Ѿ\wQ�N�׮�za�
Eb47�����u5��s*�6}�H8U�!<�mzcVc�/��?���O�R�䎾�xg��_s��u<<�o����On/���O;�p'�q;%]��JM�B|9���W����<�����N3�6��؁�$���״�=������i�?�}���F$��e�J��d�]~�7��&l�L��k�����gAk�q&��!��H��F�$������HS���&jDNT�tk�/i�K�X��RL��tL��}�Y���~(*��L.����x��)N���bV1�ΐ�u��N;H�f%��i�!���I��L�՟�va����c�A�t�Ր��J�w�d�.=�N�SDe(����7�J��%"�7̻�Ё#x�8ld�m̟�������&:Nߑ��h*��̙�ܞV��t���H[���~�r/�v��u��o��
#����Ϳ?e\�1x��U~ud��6������d�;@T����x�dG�S�T?��缫�F��b;J%bK#b�a
�}
��s�X��`}w��;���o5�zT�2B�����U5{�'|�(R;��f��}N.7w���*\�����gT��
    [7] => �prS���&�����ID�E-ײf�\j-��"�`0���YFP��������֠D�����eAk+{ж��R7ʹj׉��w{�-l4>�L�Z�%�͌�w殿��B�`�A%6\
发布评论

评论列表(0)

  1. 暂无评论