gulp-connect-php icon indicating copy to clipboard operation
gulp-connect-php copied to clipboard

Doesn't Work In Gulp 4

Open ghost opened this issue 6 years ago • 9 comments

I am currently trying to get gulp-connect-php running on a gulp4.0 version. I have tried with my existing gulp file and with a standalone project, Neither to much joy.

[10:07:09] Using gulpfile C:\development\gulp4\gulpfile.js
[10:07:09] Starting 'default'...
[10:07:09] Starting 'connect-sync'...
[10:07:09] The following tasks did not complete: default, connect-sync
[10:07:09] Did you forget to signal async completion?

This tends to be the issue that appears with the following gulpfile.js:

var gulp = require('gulp'),
    connect = require('gulp-connect-php');
    
gulp.task('connect-sync', function() {
  connect.server({});
});

gulp.task('default', gulp.series('connect-sync'));

Is there any possibility of getting this working with the new gulp4.0?

ghost avatar Jul 19 '17 09:07 ghost

@KITSDominicWhite so the official line would be "Gulp4 has not been released in a final form", but I hate it when people respond like that... so I'll do the best I can to assist.

Gulp 4 has a bunch of breaking differences from Gulp 3 one of which is that tasks are supposed to return a promise or implement the 'done parameter callback pattern'. Failure to do so will cause the task to timeout with that warning if it is being held open by anything it invoked internally.

An example of the 'done parameter callback pattern' would be:

var gulp = require('gulp'),
    connect = require('gulp-connect-php');
    
gulp.task('connect-sync', function(done) {
  connect.server({});
  // never invoking done should hold this task in a 'running' state
  // Gulp4 checks the param count on the supplied function and
  // if >= 1 waits indefinitely until a done() call is invoked.
});

gulp.task('default', gulp.series('connect-sync'));

Now, if for some reason you need this to hold until you are ready for it to complete... the following should work (Linux/Mac):

var gulp = require('gulp'),
    connect = require('gulp-connect-php');
    
gulp.task('connect-sync', function(done) {
  console.log(`Invoking gulp-connect-php on PID: ${process.pid}.`);

  connect.server({});

  // https://nodejs.org/api/process.html#process_signal_events
  // NOTE:
  // SIGINT might also work, that is sent when you issue CTRL+C
  // However there is a chance Gulp reacts to it or hides it internally.
  process.once('SIGUSR2', function() {
    console.log("Got SIGUSR2, invoking callback.");
    connect.closeServer();
    done();
  });
});

gulp.task('default', gulp.series('connect-sync'));

Now if you issue a signal via the command line:

kill -SIGUSR2 PID

That should tell the task to terminate.

(All of this is speculative, but it is what i'd try).

grmartin avatar Jul 19 '17 10:07 grmartin

@KITSDominicWhite any luck?

grmartin avatar Jul 21 '17 01:07 grmartin

Sorry @grmartin I went on holiday for a few days. I have given the first one a try with a few variants of my own, and unfortunately I haven't been able to get it working.

I am going to dig a little deeper into it and see if I can get some more information / figure it out :)

ghost avatar Jul 25 '17 07:07 ghost

@KITSDominicWhite No worries! If i can assist or if you get it working, please let me know.

grmartin avatar Jul 25 '17 20:07 grmartin

+1 to this issue

kristian avatar Jan 14 '19 21:01 kristian

+1

kirkbross avatar Mar 02 '19 22:03 kirkbross

I have gulp-connect-php + browserSync working perfectly fine using Gulp 4.0.0 + PHP 7.3.2 on Windows 10. PHP.exe for me is on %PATH%.

Does this issue only occur on Linux / macOS?

DRSDavidSoft avatar Mar 28 '19 21:03 DRSDavidSoft

Worked for me on Windows, after putting the php executable on the PATH. It just gave me a hard time, as the error message when PHP is not installed was quite hard to understand. No issues on Gulp 4.0 though.

kristian avatar Mar 29 '19 07:03 kristian

it stopped working after requiring database connection (db.php)

suprim12 avatar Mar 11 '20 06:03 suprim12