1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to execute php in a command shell?

Discussion in 'PHP' started by southwark, Mar 23, 2013.

  1. #1
    I'm reading a great book called - Webbots Spiders & Screen Scrapers-A Guide to Developing Internet Agents with PHPCURL.

    It looks very good but doesn't tell you how to do some basics. For example, it says:
    "Before we can execute the example (Downloading Files with fopen() and fgets()) , we need to examine the two ways to execute a webbot: You can run a webbot either in a browser or in a command shell.

    Problem is, it doesn't tell you how to do either.

    From what I understand, executing in a command shell is preferable. But how do I do that? Do I do it from my pc or my webhost (or both)?

    Please could someone explain this to me, or link to a good tutorial on this kind of basic.

    Suprisingly, the rest of the book seems to be aimed at beginners, so this is a strange oversight by the writer. If you're interested, it's worth a read.
     
    Solved! View solution.
    southwark, Mar 23, 2013 IP
  2. IGarret

    IGarret Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    3
    Trophy Points:
    51
    #2
    You need SSH access on your hosting to do that. Or if you are coding on local PC, you can run script in console(cmd for Windows).

    http://www.php.net/manual/en/features.commandline.usage.php
     
    IGarret, Mar 24, 2013 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    You can wrap commands in backticks `commands go here` or use exec to do stuff in command line. Or, you can just run a php script from the command line itself. If you're in Windoze, you can open a command prompt. Go to the folder where the script is located (something written that doesn't need Apache to run), and then type php.exe scriptname.php
     
    lektrikpuke, Mar 24, 2013 IP
  4. southwark

    southwark Member

    Messages:
    63
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Thanks, but that forum reads like a foreign language to me! I need things a bit simpler than that.
     
    southwark, Mar 25, 2013 IP
  5. southwark

    southwark Member

    Messages:
    63
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Thanks. Unfortunately, I need things step-by-step.

    I use php and can find my way around it pretty well. Mostly copying and pasting, admittedly, but it's effective. Unfortunately, I don't have the conceptual background so I get lost very quickly when I need to do something new.
     
    southwark, Mar 25, 2013 IP
  6. IGarret

    IGarret Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    3
    Trophy Points:
    51
    #6
    Ok, what OS you are using?
     
    IGarret, Mar 25, 2013 IP
  7. southwark

    southwark Member

    Messages:
    63
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #7
    Hey, thanks again.

    I have a pc at home with Windows vista but I also have hostgator reseller hosting with cpanel.

    Also, could someone tell me how to 'thank' or 'like' on this forum. Since it was redesigned I haven't figured out how to be 'polite' properly : )
     
    southwark, Mar 25, 2013 IP
  8. #8
    Run command line first(Win+R -> cmd).

    Then type next command:
    [PATH_TO_YOUR_PHP]\php.exe -v
    Code (markup):
    For example: "C:\Program Files\PHP\php.exe -v".

    If it will give you output with php version that means everything is right. In other case you typed wrong path to php.
     
    IGarret, Mar 25, 2013 IP
  9. southwark

    southwark Member

    Messages:
    63
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #9
    Thanks again.

    I entered the path to my xampp installation, where there is a php.exe file. It returned with the php version so I'm guessing that means all is ok?
    Does this activate php in the command shell? Do I now just type in the scripts - or can I paste them in in some way?

    Many thanks.
     
    southwark, Mar 27, 2013 IP
  10. IGarret

    IGarret Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    3
    Trophy Points:
    51
    #10
    Now you can use next syntax to run php script:

    [PATH_TO_YOUR_PHP]\php.exe [PATH_TO_YOUR_SCRIPT]\filename.php
    Code (markup):
     
    IGarret, Mar 27, 2013 IP
  11. southwark

    southwark Member

    Messages:
    63
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #11
    That worked. Thanks!
    Now I can run the scripts from the book. That's great.

    Thanks to everyone for your help - and especially IGarret.
     
    southwark, Mar 28, 2013 IP