SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: PHP cli issue!

  1. #1
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP cli issue!

    Hello! I'm running an encoding queue for a videowebsite using PHP's cli module, which allows me to run scripts outside of apache

    I run the script like

    Code:
    # php -f start.php
    And it works perfectly fine, does exactly what I want. But when I try
    to run it in the background (so that it's on 24/7) using:

    Code:
    # php -f start.php &
    The script stops parsing and dies at the first exec() it encounters.
    Why does this happen and how do I fix this?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi - well, I don't do much with CLI, however it looks like this thread isn't getting any attention here.

    I looked it up - and shouldn't it be:
    PHP Code:
    # php -f start.php & 
    (with the & instead of &).
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ruben K. View Post
    Hello! I'm running an encoding queue for a videowebsite using PHP's cli module, which allows me to run scripts outside of apache

    I run the script like

    Code:
    # php -f start.php
    And it works perfectly fine, does exactly what I want. But when I try
    to run it in the background (so that it's on 24/7) using:

    Code:
    # php -f start.php &
    The script stops parsing and dies at the first exec() it encounters.
    Why does this happen and how do I fix this?
    It is an interprepted script.. how's it going to run 24/7? A script doesn't stay in memory forever, it has a beginning and an end... simply putting it in the background wouldn't make it run 24/7.. it'll just make it run in the background untill the script has finished executing.

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catweasel View Post
    It is an interprepted script.. how's it going to run 24/7?
    You can place an infinite loop in the script, and throw in a sleep

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ruben K. View Post
    The script stops parsing and dies at the first exec() it encounters.
    Why does this happen and how do I fix this?
    How do you determine that it dies? Does it happen before or after the exec call. Do you get an error-message? How does your script look?

  6. #6
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    You can place an infinite loop in the script, and throw in a sleep
    Yes I was going to edit the post and suggest the only way you could get the script to run 24/7 would be a loop.. but then I thought that would be such a silly way to do things that I didn't bother.

  7. #7
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    How do you determine that it dies? Does it happen before or after the exec call. Do you get an error-message? How does your script look?
    In my script I output to a log, and I exec() ffmpeg which outputs to a different log. I find that when I try to run it in the background, the php script log stopped at the exec() and the ffmpeg exec() call log is empty

    The & thing arkinstall suggested will not work, as this is the command I type into a terminal and & is not allowed
    Last edited by Ruben K.; Nov 11, 2007 at 04:25.

  8. #8
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the following work from the command line:
    Code:
    php -r "while(1)error_log(\`pwd\`,3,'log');" & tail -f log

  9. #9
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    Does the following work from the command line:
    Code:
    php -r "while(1)error_log(\`pwd\`,3,'log');" & tail -f log
    It would probably kill my machine

  10. #10
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ctrl-c
    man fg
    man jobs

  11. #11
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    Does the following work from the command line:
    Code:
    php -r "while(1)error_log(\`pwd\`,3,'log');" & tail -f log
    This works with no error, other than tail -f won't open log because it doesn't exist yet.
    It runs in the background until I kill it's pid

  12. #12
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, now we know there's nothing wrong with your system or php installation. Can you post your non-working script then?

  13. #13
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I accidentally found a 'fix' (more like a hack)!

    I was running the script in a terminal, and my terminal timed out. The script has been running ever since!

    What a pleasant surprise :P


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •