Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 642
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: March 26, 20252025-03-26T09:47:31+00:00 2025-03-26T09:47:31+00:00In: PHP

PHP exec() resulting in infinite/forever loop when calling another PHP script

  • 0
  • 0
PHP exec() resulting in infinite/forever loop when calling another PHP script

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:

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:

/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\񐄟��Sj��.�r�����삵o0?��9�1i���7�wd¯*�o���L활��W�
    [8] => �����&,�:b�np�k�`���M�Gϼ��L\4�>z,���^%�r�4��x���=f,v�   �1z+���t��рC���w�*�<��*�sU�^�x�u�8�h����1W�҂��ϧV�ԏdu����T_�%���?ix�WD� w��9˴A��C}j�BߥiBS�Bz�;;�'��뚐�^��9������1AXV��7-��%����ב�O��Rjc������v�d�&��,���fႣ�������,�  �\��V�
    [9] => >y����Z�!��=��=��=�!T%��۳Ic�4��5��PucJ�?,�D%菱�����w�^��V0�����0.�C�7���WK˳Jv�������c���X0�L�4��M���]������h���R�7�����y�#!Ѧ�~�1|�>?��3  o��3�\����,��_��<�\�ޚ�B{����j�gB��߻Ab�,��v_��ڄ�ܦa>F-j��5�R����ejԐ��l
    [10] => �Nj��=��dW(�ʔP�A~NJ��R��T[/C��o��u�օ@�,NL�o����
    [11] => ͧ�^r�ܫ��A��n""e�6č)���Ck|���Y��h59�b�n���4�6Xq�    I��'`��Z��%��b"H���<�a���QZ���^�t/�H��811��5��>��;���wxs,��������ɬ���u)qS8,��W���II�v�o'�{�E��Js��P���^��v�E3CS��x���2���F��[���m
�����
    [12] => Q~&�������?�,�I��{�����T���{�@�b�wH��S��I�4W6M�oW��D��Q��R�E�   #� (M_��LS�Z���J��!�c�Z*��k�P�)E�,7_ߐ]n-�eLI�}L�z�[����| Y.O��k�/O�\���L|"?GG��A�wu�G�+����R�(�����v���?]~�,w4� ���0��/l'��J`�pu��<�:�Kԛm�<��m���`2�����bi���0<�!�Ы{�����O��Y��?���_9��q��\o�ySo��-[p�KM·��p5K�UIh�r5��N7���8;���I�w55$����˼��3�F��-f�N�9���Ԫ�l���\���&��X1�|��^��p&�,q!#�B7o�+�W�}����6�`i]r�l���&Q�Wa]d^�����>�    �+���qb=B�<�t����O��&��F����_�wG5��G�n.ɉ�ւ��4�?���b?���Π�fY�xM�j`��ae6։oqd�
    [13] => >�Y��T�0����YIe]�z�86B���(�Ήj!��Lq�f#�~�U��<\r:Ωf,��8�4ţ����)M�j1T�7��ч|z��@&�1D(¦3��r6mվ�g�ɂ�>U��ƈ@����C�~�Y�?��
����|g����B�Y����c�H(��k�]Gp����
<�d��#��Uɺ/��Ј4��f������(��%Y ����t��8J+��*_�_�n���r9�1y#��B;�!5#I�a0n�*��U�~�H�^���o(�N��K�o����U�:�Q{���ON
    [14] => ���8.Ֆ�Y� ����*)���u1���\���ʿ�/�VD[�b��n<��e��2�4�eJ�b|�?kt�7�b(�����i5Xݯmw����pn������M+�l#�A�>�~1~<�w"՗��?�l?�k11/{L����"�,�*�G����.�S��B�飕�h��k�K���x�w}xZ`v���,��#9<��Ȉ�=����Z?oOc��:+OA��R�$� +v�M{
�Ԙ�QsI��9k�TF��U*oV}��|�F��Z��&����]R&�a��|������ŅKNS��?4r���~�M�"�G� ��S}����7D����S:���*Uk�<���;��\�!;B5F�tt�|�ʰ�!h�j$�; ��=��`[{a�%<�zyt���k�%'u�������u]D��.�n�¢Ӽ��@����?wK��~�@�
)
 */

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

$output = null;
$return_val = -1;
exec($cmd, $output, $return_val);
echo "
Return val: " . print_r($return_val, true) . "

";
echo "

Output: " . print_r($output, true) . "

";

This and this haven’t helped. Any ideas?

0
  • 0 0 Answers
  • 29 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.