Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Ok, let's assume I have PHP running as compiled CGI on my server.

    If I do the following cron:

    Code:
    php /home/username/public_html/scriptname.php
    1. How does that process execute?
    2. Is there a session?
    3. Is there a client?
    4. Is there a time-limit?
    5. What if there's an infinite loop? Will it bog down the server until I reboot?
    6. Is there a way to thread the processes or limit CPU % / flops?

    Thanks

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    1. It'll run under whoever's crontab it was created.
    2. Unlikely as there will be no cookies.
    3. Also unlikely for the same reason (there was no HTTP request).
    4. It will probably inherit php.ini's time limit setting.
    5. The time limit should kill it. If not, some hosts (definitely Hosting Matters) will automatically kill a runaway process.
    6. You can nice the process (have it run at a different priority). There is probably a way to restrict it to a single CPU core or completely limit its usage as well.

    I know that wasn't very helpful but hopefully there was something in there.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Ok, well here's my issue... I have a file that I want to import into a database on a regular basis, so I set it up as a cron job. The file is 700 megs, probably on the order of 4 million records. I assume it's going to take several hours to run. How would I get cron to execute that without php.ini getting in the way? There's an override for the default timeout, right?

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    [minicode]php --help[/minicode] is your friend. Of particular interest:

    Code:
      -n               No php.ini file will be used
      -d foo[=bar]     Define INI entry foo with value 'bar'
    Also of interest is [phpfunction]set_time_limit[/phpfunction] (0 likely being the value you're looking for).

    Since you won't want your server dead during the cron job, you'll want to use nice, as filburt pointed out. [minicode]man nice[/minicode] is your friend, but basically the way it works is that you run your command like so:

    [minicode]nice -n 19 php /home/username/public_html/scriptname.php[/minicode]

    That will give the resulting php process the absolutely lowest priority. The nice range runs from -20 to 19, with -20 being the most favorable. Because some computers have a slightly different nice range, you may want to set the nice number to something higher, just to be sure, though if you're running Linux 19 should be what you need.

    In addition, there are a couple of other programs that may help you out. CPU limit can be used to set a CPU limit based on percentage and the [minicode]schedutils[/minicode] package contains the [minicode]taskset[/minicode] program that allows you to set processor affinity (i.e., limit a process to certain CPUs), which nice does not do, as described on this site. [minicode]schedutils[/minicode] also includes a program that gives you the ability to change scheduling priority and policy stuff, but I think you'll have to download it and hit the man pages to find out how it works.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Hey Shadow,

    Thanks for all the info. I just looked at your profile and saw you go to Ga Tech. My cousin Bobby is there, going into his sophomore year this fall. What year are you?

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Hey Shadow,

    Thanks for all the info. I just looked at your profile and saw you go to Ga Tech. My cousin Bobby is there, going into his sophomore year this fall. What year are you?

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I'm going into my fourth year in August. What's he majoring in?

    EDIT: Nm. Creepily enough, in the modern world, it's relatively easy to find out. ME, right?

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Quote Originally Posted by Shadowfiend
    I'm going into my fourth year in August. What's he majoring in?

    EDIT: Nm. Creepily enough, in the modern world, it's relatively easy to find out. ME, right?
    Right.

  10. #9
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Yeah. Facebook is cool, but it kinda creeped me out just then O_O


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:21 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com