Asked  7 Months ago    Answers:  5   Viewed   35 times

If I want to execute a php script, i just point the browser to

But if i want to execute a specific function inside myscript.php, is there a way? something like




One quick way is to do things like

then in myscript.php

if(function_exists($_GET['f'])) {

But please, for the love of all kittens, don't abuse this.

Wednesday, March 31, 2021
answered 7 Months ago

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario:

Related usability ticket:

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
answered 7 Months ago

You can't call PHP functions directly. However, if the php file is formatted how you displayed here with only two functions you could pass a flag in as a POST field and have a logic block determine which function call based on that flag. It's not ideal but it would work for your purposes. However, this would force the page to refresh and you would probably have to load a different page after the function returns so you may want to simply implement this as an ajax call to avoid the page refresh.

Edit based on your comment (Using jQuery Ajax):

I am using the .ajax() jQuery function. My intentions create one php file that contains multiple functions for different html forms. – tmhenson

Well in this case, you can have your file contain the logic block to "route" the request to the right function and finally return the result.

I'll try to provide an option for what you want to do based on some simple jQuery. Say you have something like this:

Java Script:

    e.preventDefault(); // prevents submit event if button is a submit
    e.preventDefault(); // prevents submit event if button is a submit

function ajax_route(action_requested){ 
    $.post("ajax_handler.php", {action : action_requested}, function(data){
        if (data.length>0){ 
            alert("Hoorah! Completed the action requested: "+action_requested); 

PHP (inside ajax_handler.php)

// make sure u have an action to take
        case 'ap': addPerson(); break;
        case 'se': sendEmail(); break;
        default: break;

function addPerson() {
    //do stuff here 

function sendEmail() {
    //do some stuff here 
Wednesday, March 31, 2021
answered 7 Months ago

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
answered 5 Months ago

This is how I do it. It works like a charm.

# shell execute PHP
def php(code):
  # open process
  p = Popen(['php'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, close_fds=True)

  # read output
  o = p.communicate(code)[0]

  # kill process
    os.kill(, signal.SIGTERM)

  # return
  return o

To execute a particular file do this:

width = 100
height = 100

code = """<?php

  echo start(""" + width + """, """ + height + """);

res = php(code)
Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :